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

// SetStickerSetThumbnailRequest represents TL type `setStickerSetThumbnail#63fe6932`.
type SetStickerSetThumbnailRequest struct {
	// Sticker set owner; ignored for regular users
	UserID int64
	// Sticker set name. The sticker set must be owned by the current user
	Name string
	// Thumbnail to set; pass null to remove the sticker set thumbnail
	Thumbnail InputFileClass
	// Format of the thumbnail; pass null if thumbnail is removed
	Format StickerFormatClass
}

// SetStickerSetThumbnailRequestTypeID is TL type id of SetStickerSetThumbnailRequest.
const SetStickerSetThumbnailRequestTypeID = 0x63fe6932

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

func (s *SetStickerSetThumbnailRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.UserID == 0) {
		return false
	}
	if !(s.Name == "") {
		return false
	}
	if !(s.Thumbnail == nil) {
		return false
	}
	if !(s.Format == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetStickerSetThumbnailRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setStickerSetThumbnail",
		ID:   SetStickerSetThumbnailRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
		{
			Name:       "Name",
			SchemaName: "name",
		},
		{
			Name:       "Thumbnail",
			SchemaName: "thumbnail",
		},
		{
			Name:       "Format",
			SchemaName: "format",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetStickerSetThumbnailRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setStickerSetThumbnail#63fe6932 as nil")
	}
	b.PutID(SetStickerSetThumbnailRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetStickerSetThumbnailRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setStickerSetThumbnail#63fe6932 as nil")
	}
	b.PutInt53(s.UserID)
	b.PutString(s.Name)
	if s.Thumbnail == nil {
		return fmt.Errorf("unable to encode setStickerSetThumbnail#63fe6932: field thumbnail is nil")
	}
	if err := s.Thumbnail.Encode(b); err != nil {
		return fmt.Errorf("unable to encode setStickerSetThumbnail#63fe6932: field thumbnail: %w", err)
	}
	if s.Format == nil {
		return fmt.Errorf("unable to encode setStickerSetThumbnail#63fe6932: field format is nil")
	}
	if err := s.Format.Encode(b); err != nil {
		return fmt.Errorf("unable to encode setStickerSetThumbnail#63fe6932: field format: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *SetStickerSetThumbnailRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setStickerSetThumbnail#63fe6932 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setStickerSetThumbnail#63fe6932: field user_id: %w", err)
		}
		s.UserID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode setStickerSetThumbnail#63fe6932: field name: %w", err)
		}
		s.Name = value
	}
	{
		value, err := DecodeInputFile(b)
		if err != nil {
			return fmt.Errorf("unable to decode setStickerSetThumbnail#63fe6932: field thumbnail: %w", err)
		}
		s.Thumbnail = value
	}
	{
		value, err := DecodeStickerFormat(b)
		if err != nil {
			return fmt.Errorf("unable to decode setStickerSetThumbnail#63fe6932: field format: %w", err)
		}
		s.Format = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetStickerSetThumbnailRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setStickerSetThumbnail#63fe6932 as nil")
	}
	b.ObjStart()
	b.PutID("setStickerSetThumbnail")
	b.Comma()
	b.FieldStart("user_id")
	b.PutInt53(s.UserID)
	b.Comma()
	b.FieldStart("name")
	b.PutString(s.Name)
	b.Comma()
	b.FieldStart("thumbnail")
	if s.Thumbnail == nil {
		return fmt.Errorf("unable to encode setStickerSetThumbnail#63fe6932: field thumbnail is nil")
	}
	if err := s.Thumbnail.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode setStickerSetThumbnail#63fe6932: field thumbnail: %w", err)
	}
	b.Comma()
	b.FieldStart("format")
	if s.Format == nil {
		return fmt.Errorf("unable to encode setStickerSetThumbnail#63fe6932: field format is nil")
	}
	if err := s.Format.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode setStickerSetThumbnail#63fe6932: field format: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setStickerSetThumbnail"); err != nil {
				return fmt.Errorf("unable to decode setStickerSetThumbnail#63fe6932: %w", err)
			}
		case "user_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode setStickerSetThumbnail#63fe6932: field user_id: %w", err)
			}
			s.UserID = value
		case "name":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode setStickerSetThumbnail#63fe6932: field name: %w", err)
			}
			s.Name = value
		case "thumbnail":
			value, err := DecodeTDLibJSONInputFile(b)
			if err != nil {
				return fmt.Errorf("unable to decode setStickerSetThumbnail#63fe6932: field thumbnail: %w", err)
			}
			s.Thumbnail = value
		case "format":
			value, err := DecodeTDLibJSONStickerFormat(b)
			if err != nil {
				return fmt.Errorf("unable to decode setStickerSetThumbnail#63fe6932: field format: %w", err)
			}
			s.Format = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetUserID returns value of UserID field.
func (s *SetStickerSetThumbnailRequest) GetUserID() (value int64) {
	if s == nil {
		return
	}
	return s.UserID
}

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

// GetThumbnail returns value of Thumbnail field.
func (s *SetStickerSetThumbnailRequest) GetThumbnail() (value InputFileClass) {
	if s == nil {
		return
	}
	return s.Thumbnail
}

// GetFormat returns value of Format field.
func (s *SetStickerSetThumbnailRequest) GetFormat() (value StickerFormatClass) {
	if s == nil {
		return
	}
	return s.Format
}

// SetStickerSetThumbnail invokes method setStickerSetThumbnail#63fe6932 returning error if any.
func (c *Client) SetStickerSetThumbnail(ctx context.Context, request *SetStickerSetThumbnailRequest) error {
	var ok Ok

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