// Code generated by gotdgen, DO NOT EDIT.

package tg

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{}
)

// AccountGetUniqueGiftChatThemesRequest represents TL type `account.getUniqueGiftChatThemes#e42ce9c9`.
// Obtain all chat themes »¹ associated to owned collectible gifts »².
//
// Links:
//  1. https://core.telegram.org/api/themes#chat-themes
//  2. https://core.telegram.org/api/gifts#collectible-gifts
//
// See https://core.telegram.org/method/account.getUniqueGiftChatThemes for reference.
type AccountGetUniqueGiftChatThemesRequest struct {
	// Offset for pagination¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	Offset string
	// Maximum number of results to return, see pagination¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	Limit int
	// Hash from a previously returned account.chatThemes¹ constructor, to avoid returning
	// any result if the theme list hasn't changed.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/account.chatThemes
	Hash int64
}

// AccountGetUniqueGiftChatThemesRequestTypeID is TL type id of AccountGetUniqueGiftChatThemesRequest.
const AccountGetUniqueGiftChatThemesRequestTypeID = 0xe42ce9c9

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

func (g *AccountGetUniqueGiftChatThemesRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Offset == "") {
		return false
	}
	if !(g.Limit == 0) {
		return false
	}
	if !(g.Hash == 0) {
		return false
	}

	return true
}

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

// FillFrom fills AccountGetUniqueGiftChatThemesRequest from given interface.
func (g *AccountGetUniqueGiftChatThemesRequest) FillFrom(from interface {
	GetOffset() (value string)
	GetLimit() (value int)
	GetHash() (value int64)
}) {
	g.Offset = from.GetOffset()
	g.Limit = from.GetLimit()
	g.Hash = from.GetHash()
}

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

// TypeName returns name of type in TL schema.
func (*AccountGetUniqueGiftChatThemesRequest) TypeName() string {
	return "account.getUniqueGiftChatThemes"
}

// TypeInfo returns info about TL type.
func (g *AccountGetUniqueGiftChatThemesRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "account.getUniqueGiftChatThemes",
		ID:   AccountGetUniqueGiftChatThemesRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Offset",
			SchemaName: "offset",
		},
		{
			Name:       "Limit",
			SchemaName: "limit",
		},
		{
			Name:       "Hash",
			SchemaName: "hash",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *AccountGetUniqueGiftChatThemesRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode account.getUniqueGiftChatThemes#e42ce9c9 as nil")
	}
	b.PutID(AccountGetUniqueGiftChatThemesRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *AccountGetUniqueGiftChatThemesRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode account.getUniqueGiftChatThemes#e42ce9c9 as nil")
	}
	b.PutString(g.Offset)
	b.PutInt(g.Limit)
	b.PutLong(g.Hash)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *AccountGetUniqueGiftChatThemesRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode account.getUniqueGiftChatThemes#e42ce9c9 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode account.getUniqueGiftChatThemes#e42ce9c9: field offset: %w", err)
		}
		g.Offset = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode account.getUniqueGiftChatThemes#e42ce9c9: field limit: %w", err)
		}
		g.Limit = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode account.getUniqueGiftChatThemes#e42ce9c9: field hash: %w", err)
		}
		g.Hash = value
	}
	return nil
}

// GetOffset returns value of Offset field.
func (g *AccountGetUniqueGiftChatThemesRequest) GetOffset() (value string) {
	if g == nil {
		return
	}
	return g.Offset
}

// GetLimit returns value of Limit field.
func (g *AccountGetUniqueGiftChatThemesRequest) GetLimit() (value int) {
	if g == nil {
		return
	}
	return g.Limit
}

// GetHash returns value of Hash field.
func (g *AccountGetUniqueGiftChatThemesRequest) GetHash() (value int64) {
	if g == nil {
		return
	}
	return g.Hash
}

// AccountGetUniqueGiftChatThemes invokes method account.getUniqueGiftChatThemes#e42ce9c9 returning error if any.
// Obtain all chat themes »¹ associated to owned collectible gifts »².
//
// Links:
//  1. https://core.telegram.org/api/themes#chat-themes
//  2. https://core.telegram.org/api/gifts#collectible-gifts
//
// See https://core.telegram.org/method/account.getUniqueGiftChatThemes for reference.
func (c *Client) AccountGetUniqueGiftChatThemes(ctx context.Context, request *AccountGetUniqueGiftChatThemesRequest) (AccountChatThemesClass, error) {
	var result AccountChatThemesBox

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