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

// SetStickerEmojisRequest represents TL type `setStickerEmojis#d9ec0431`.
type SetStickerEmojisRequest struct {
	// Sticker
	Sticker InputFileClass
	// New string with 1-20 emoji corresponding to the sticker
	Emojis string
}

// SetStickerEmojisRequestTypeID is TL type id of SetStickerEmojisRequest.
const SetStickerEmojisRequestTypeID = 0xd9ec0431

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

func (s *SetStickerEmojisRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Sticker == nil) {
		return false
	}
	if !(s.Emojis == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetStickerEmojisRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setStickerEmojis",
		ID:   SetStickerEmojisRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Sticker",
			SchemaName: "sticker",
		},
		{
			Name:       "Emojis",
			SchemaName: "emojis",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetStickerEmojisRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setStickerEmojis#d9ec0431 as nil")
	}
	b.PutID(SetStickerEmojisRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetStickerEmojisRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setStickerEmojis#d9ec0431 as nil")
	}
	if s.Sticker == nil {
		return fmt.Errorf("unable to encode setStickerEmojis#d9ec0431: field sticker is nil")
	}
	if err := s.Sticker.Encode(b); err != nil {
		return fmt.Errorf("unable to encode setStickerEmojis#d9ec0431: field sticker: %w", err)
	}
	b.PutString(s.Emojis)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *SetStickerEmojisRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setStickerEmojis#d9ec0431 to nil")
	}
	{
		value, err := DecodeInputFile(b)
		if err != nil {
			return fmt.Errorf("unable to decode setStickerEmojis#d9ec0431: field sticker: %w", err)
		}
		s.Sticker = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode setStickerEmojis#d9ec0431: field emojis: %w", err)
		}
		s.Emojis = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetStickerEmojisRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setStickerEmojis#d9ec0431 as nil")
	}
	b.ObjStart()
	b.PutID("setStickerEmojis")
	b.Comma()
	b.FieldStart("sticker")
	if s.Sticker == nil {
		return fmt.Errorf("unable to encode setStickerEmojis#d9ec0431: field sticker is nil")
	}
	if err := s.Sticker.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode setStickerEmojis#d9ec0431: field sticker: %w", err)
	}
	b.Comma()
	b.FieldStart("emojis")
	b.PutString(s.Emojis)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setStickerEmojis"); err != nil {
				return fmt.Errorf("unable to decode setStickerEmojis#d9ec0431: %w", err)
			}
		case "sticker":
			value, err := DecodeTDLibJSONInputFile(b)
			if err != nil {
				return fmt.Errorf("unable to decode setStickerEmojis#d9ec0431: field sticker: %w", err)
			}
			s.Sticker = value
		case "emojis":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode setStickerEmojis#d9ec0431: field emojis: %w", err)
			}
			s.Emojis = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetSticker returns value of Sticker field.
func (s *SetStickerEmojisRequest) GetSticker() (value InputFileClass) {
	if s == nil {
		return
	}
	return s.Sticker
}

// GetEmojis returns value of Emojis field.
func (s *SetStickerEmojisRequest) GetEmojis() (value string) {
	if s == nil {
		return
	}
	return s.Emojis
}

// SetStickerEmojis invokes method setStickerEmojis#d9ec0431 returning error if any.
func (c *Client) SetStickerEmojis(ctx context.Context, request *SetStickerEmojisRequest) error {
	var ok Ok

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