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

// SetCustomEmojiStickerSetThumbnailRequest represents TL type `setCustomEmojiStickerSetThumbnail#bd12e0ea`.
type SetCustomEmojiStickerSetThumbnailRequest struct {
	// Sticker set name. The sticker set must be owned by the current user
	Name string
	// Identifier of the custom emoji from the sticker set, which will be set as sticker set
	// thumbnail; pass 0 to remove the sticker set thumbnail
	CustomEmojiID int64
}

// SetCustomEmojiStickerSetThumbnailRequestTypeID is TL type id of SetCustomEmojiStickerSetThumbnailRequest.
const SetCustomEmojiStickerSetThumbnailRequestTypeID = 0xbd12e0ea

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

func (s *SetCustomEmojiStickerSetThumbnailRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Name == "") {
		return false
	}
	if !(s.CustomEmojiID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetCustomEmojiStickerSetThumbnailRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setCustomEmojiStickerSetThumbnail",
		ID:   SetCustomEmojiStickerSetThumbnailRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Name",
			SchemaName: "name",
		},
		{
			Name:       "CustomEmojiID",
			SchemaName: "custom_emoji_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetCustomEmojiStickerSetThumbnailRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setCustomEmojiStickerSetThumbnail#bd12e0ea as nil")
	}
	b.PutID(SetCustomEmojiStickerSetThumbnailRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetCustomEmojiStickerSetThumbnailRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setCustomEmojiStickerSetThumbnail#bd12e0ea as nil")
	}
	b.PutString(s.Name)
	b.PutLong(s.CustomEmojiID)
	return nil
}

// Decode implements bin.Decoder.
func (s *SetCustomEmojiStickerSetThumbnailRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setCustomEmojiStickerSetThumbnail#bd12e0ea to nil")
	}
	if err := b.ConsumeID(SetCustomEmojiStickerSetThumbnailRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode setCustomEmojiStickerSetThumbnail#bd12e0ea: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SetCustomEmojiStickerSetThumbnailRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setCustomEmojiStickerSetThumbnail#bd12e0ea to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode setCustomEmojiStickerSetThumbnail#bd12e0ea: field name: %w", err)
		}
		s.Name = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode setCustomEmojiStickerSetThumbnail#bd12e0ea: field custom_emoji_id: %w", err)
		}
		s.CustomEmojiID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetCustomEmojiStickerSetThumbnailRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setCustomEmojiStickerSetThumbnail#bd12e0ea as nil")
	}
	b.ObjStart()
	b.PutID("setCustomEmojiStickerSetThumbnail")
	b.Comma()
	b.FieldStart("name")
	b.PutString(s.Name)
	b.Comma()
	b.FieldStart("custom_emoji_id")
	b.PutLong(s.CustomEmojiID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SetCustomEmojiStickerSetThumbnailRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode setCustomEmojiStickerSetThumbnail#bd12e0ea to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setCustomEmojiStickerSetThumbnail"); err != nil {
				return fmt.Errorf("unable to decode setCustomEmojiStickerSetThumbnail#bd12e0ea: %w", err)
			}
		case "name":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode setCustomEmojiStickerSetThumbnail#bd12e0ea: field name: %w", err)
			}
			s.Name = value
		case "custom_emoji_id":
			value, err := b.Long()
			if err != nil {
				return fmt.Errorf("unable to decode setCustomEmojiStickerSetThumbnail#bd12e0ea: field custom_emoji_id: %w", err)
			}
			s.CustomEmojiID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetName returns value of Name field.
func (s *SetCustomEmojiStickerSetThumbnailRequest) GetName() (value string) {
	if s == nil {
		return
	}
	return s.Name
}

// GetCustomEmojiID returns value of CustomEmojiID field.
func (s *SetCustomEmojiStickerSetThumbnailRequest) GetCustomEmojiID() (value int64) {
	if s == nil {
		return
	}
	return s.CustomEmojiID
}

// SetCustomEmojiStickerSetThumbnail invokes method setCustomEmojiStickerSetThumbnail#bd12e0ea returning error if any.
func (c *Client) SetCustomEmojiStickerSetThumbnail(ctx context.Context, request *SetCustomEmojiStickerSetThumbnailRequest) error {
	var ok Ok

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