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

// AccountGetCollectibleEmojiStatusesRequest represents TL type `account.getCollectibleEmojiStatuses#2e7b4543`.
// Obtain a list of emoji statuses »¹ for owned collectible gifts².
//
// Links:
//  1. https://core.telegram.org/api/emoji-status
//  2. https://core.telegram.org/api/gifts#collectible-gifts
//
// See https://core.telegram.org/method/account.getCollectibleEmojiStatuses for reference.
type AccountGetCollectibleEmojiStatusesRequest struct {
	// Hash for pagination¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	Hash int64
}

// AccountGetCollectibleEmojiStatusesRequestTypeID is TL type id of AccountGetCollectibleEmojiStatusesRequest.
const AccountGetCollectibleEmojiStatusesRequestTypeID = 0x2e7b4543

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

func (g *AccountGetCollectibleEmojiStatusesRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Hash == 0) {
		return false
	}

	return true
}

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

// FillFrom fills AccountGetCollectibleEmojiStatusesRequest from given interface.
func (g *AccountGetCollectibleEmojiStatusesRequest) FillFrom(from interface {
	GetHash() (value int64)
}) {
	g.Hash = from.GetHash()
}

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

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

// TypeInfo returns info about TL type.
func (g *AccountGetCollectibleEmojiStatusesRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "account.getCollectibleEmojiStatuses",
		ID:   AccountGetCollectibleEmojiStatusesRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Hash",
			SchemaName: "hash",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *AccountGetCollectibleEmojiStatusesRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode account.getCollectibleEmojiStatuses#2e7b4543 as nil")
	}
	b.PutID(AccountGetCollectibleEmojiStatusesRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *AccountGetCollectibleEmojiStatusesRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode account.getCollectibleEmojiStatuses#2e7b4543 as nil")
	}
	b.PutLong(g.Hash)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *AccountGetCollectibleEmojiStatusesRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode account.getCollectibleEmojiStatuses#2e7b4543 to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode account.getCollectibleEmojiStatuses#2e7b4543: field hash: %w", err)
		}
		g.Hash = value
	}
	return nil
}

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

// AccountGetCollectibleEmojiStatuses invokes method account.getCollectibleEmojiStatuses#2e7b4543 returning error if any.
// Obtain a list of emoji statuses »¹ for owned collectible gifts².
//
// Links:
//  1. https://core.telegram.org/api/emoji-status
//  2. https://core.telegram.org/api/gifts#collectible-gifts
//
// See https://core.telegram.org/method/account.getCollectibleEmojiStatuses for reference.
func (c *Client) AccountGetCollectibleEmojiStatuses(ctx context.Context, hash int64) (AccountEmojiStatusesClass, error) {
	var result AccountEmojiStatusesBox

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