// Code generated by gotdgen, DO NOT EDIT.

package tdapi

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdjson"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdp"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
)

// No-op definition for keeping imports.
var (
	_ = bin.Buffer{}
	_ = context.Background()
	_ = fmt.Stringer(nil)
	_ = strings.Builder{}
	_ = errors.Is
	_ = multierr.AppendInto
	_ = sort.Ints
	_ = tdp.Format
	_ = tgerr.Error{}
	_ = tdjson.Encoder{}
)

// GetRecommendedChatsRequest represents TL type `getRecommendedChats#d9438d71`.
type GetRecommendedChatsRequest struct {
}

// GetRecommendedChatsRequestTypeID is TL type id of GetRecommendedChatsRequest.
const GetRecommendedChatsRequestTypeID = 0xd9438d71

// Ensuring interfaces in compile-time for GetRecommendedChatsRequest.
var (
	_ bin.Encoder     = &GetRecommendedChatsRequest{}
	_ bin.Decoder     = &GetRecommendedChatsRequest{}
	_ bin.BareEncoder = &GetRecommendedChatsRequest{}
	_ bin.BareDecoder = &GetRecommendedChatsRequest{}
)

func (g *GetRecommendedChatsRequest) Zero() bool {
	if g == nil {
		return true
	}

	return true
}

// String implements fmt.Stringer.
func (g *GetRecommendedChatsRequest) String() string {
	if g == nil {
		return "GetRecommendedChatsRequest(nil)"
	}
	type Alias GetRecommendedChatsRequest
	return fmt.Sprintf("GetRecommendedChatsRequest%+v", Alias(*g))
}

// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*GetRecommendedChatsRequest) TypeID() uint32 {
	return GetRecommendedChatsRequestTypeID
}

// TypeName returns name of type in TL schema.
func (*GetRecommendedChatsRequest) TypeName() string {
	return "getRecommendedChats"
}

// TypeInfo returns info about TL type.
func (g *GetRecommendedChatsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getRecommendedChats",
		ID:   GetRecommendedChatsRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetRecommendedChatsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getRecommendedChats#d9438d71 as nil")
	}
	b.PutID(GetRecommendedChatsRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetRecommendedChatsRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getRecommendedChats#d9438d71 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (g *GetRecommendedChatsRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getRecommendedChats#d9438d71 to nil")
	}
	if err := b.ConsumeID(GetRecommendedChatsRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode getRecommendedChats#d9438d71: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *GetRecommendedChatsRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getRecommendedChats#d9438d71 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetRecommendedChatsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getRecommendedChats#d9438d71 as nil")
	}
	b.ObjStart()
	b.PutID("getRecommendedChats")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GetRecommendedChatsRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if g == nil {
		return fmt.Errorf("can't decode getRecommendedChats#d9438d71 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getRecommendedChats"); err != nil {
				return fmt.Errorf("unable to decode getRecommendedChats#d9438d71: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetRecommendedChats invokes method getRecommendedChats#d9438d71 returning error if any.
func (c *Client) GetRecommendedChats(ctx context.Context) (*Chats, error) {
	var result Chats

	request := &GetRecommendedChatsRequest{}
	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return nil, err
	}
	return &result, nil
}
