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

// AccountGetDefaultBackgroundEmojisRequest represents TL type `account.getDefaultBackgroundEmojis#a60ab9ce`.
// Get a set of suggested custom emoji stickers¹ that can be used in an accent color
// pattern².
//
// Links:
//  1. https://core.telegram.org/api/custom-emoji
//  2. https://core.telegram.org/api/colors
//
// See https://core.telegram.org/method/account.getDefaultBackgroundEmojis for reference.
type AccountGetDefaultBackgroundEmojisRequest struct {
	// Hash used for caching, for more info click here¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets#hash-generation
	Hash int64
}

// AccountGetDefaultBackgroundEmojisRequestTypeID is TL type id of AccountGetDefaultBackgroundEmojisRequest.
const AccountGetDefaultBackgroundEmojisRequestTypeID = 0xa60ab9ce

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

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

	return true
}

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

// FillFrom fills AccountGetDefaultBackgroundEmojisRequest from given interface.
func (g *AccountGetDefaultBackgroundEmojisRequest) 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 (*AccountGetDefaultBackgroundEmojisRequest) TypeID() uint32 {
	return AccountGetDefaultBackgroundEmojisRequestTypeID
}

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

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

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

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

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

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

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

// AccountGetDefaultBackgroundEmojis invokes method account.getDefaultBackgroundEmojis#a60ab9ce returning error if any.
// Get a set of suggested custom emoji stickers¹ that can be used in an accent color
// pattern².
//
// Links:
//  1. https://core.telegram.org/api/custom-emoji
//  2. https://core.telegram.org/api/colors
//
// See https://core.telegram.org/method/account.getDefaultBackgroundEmojis for reference.
func (c *Client) AccountGetDefaultBackgroundEmojis(ctx context.Context, hash int64) (EmojiListClass, error) {
	var result EmojiListBox

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