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

// SetSupergroupCustomEmojiStickerSetRequest represents TL type `setSupergroupCustomEmojiStickerSet#4f3552af`.
type SetSupergroupCustomEmojiStickerSetRequest struct {
	// Identifier of the supergroup
	SupergroupID int64
	// New value of the custom emoji sticker set identifier for the supergroup. Use 0 to
	// remove the custom emoji sticker set in the supergroup
	CustomEmojiStickerSetID int64
}

// SetSupergroupCustomEmojiStickerSetRequestTypeID is TL type id of SetSupergroupCustomEmojiStickerSetRequest.
const SetSupergroupCustomEmojiStickerSetRequestTypeID = 0x4f3552af

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

func (s *SetSupergroupCustomEmojiStickerSetRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.SupergroupID == 0) {
		return false
	}
	if !(s.CustomEmojiStickerSetID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetSupergroupCustomEmojiStickerSetRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setSupergroupCustomEmojiStickerSet",
		ID:   SetSupergroupCustomEmojiStickerSetRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "SupergroupID",
			SchemaName: "supergroup_id",
		},
		{
			Name:       "CustomEmojiStickerSetID",
			SchemaName: "custom_emoji_sticker_set_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetSupergroupCustomEmojiStickerSetRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setSupergroupCustomEmojiStickerSet#4f3552af as nil")
	}
	b.PutID(SetSupergroupCustomEmojiStickerSetRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetSupergroupCustomEmojiStickerSetRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setSupergroupCustomEmojiStickerSet#4f3552af as nil")
	}
	b.PutInt53(s.SupergroupID)
	b.PutLong(s.CustomEmojiStickerSetID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *SetSupergroupCustomEmojiStickerSetRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setSupergroupCustomEmojiStickerSet#4f3552af to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setSupergroupCustomEmojiStickerSet#4f3552af: field supergroup_id: %w", err)
		}
		s.SupergroupID = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode setSupergroupCustomEmojiStickerSet#4f3552af: field custom_emoji_sticker_set_id: %w", err)
		}
		s.CustomEmojiStickerSetID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetSupergroupCustomEmojiStickerSetRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setSupergroupCustomEmojiStickerSet#4f3552af as nil")
	}
	b.ObjStart()
	b.PutID("setSupergroupCustomEmojiStickerSet")
	b.Comma()
	b.FieldStart("supergroup_id")
	b.PutInt53(s.SupergroupID)
	b.Comma()
	b.FieldStart("custom_emoji_sticker_set_id")
	b.PutLong(s.CustomEmojiStickerSetID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setSupergroupCustomEmojiStickerSet"); err != nil {
				return fmt.Errorf("unable to decode setSupergroupCustomEmojiStickerSet#4f3552af: %w", err)
			}
		case "supergroup_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode setSupergroupCustomEmojiStickerSet#4f3552af: field supergroup_id: %w", err)
			}
			s.SupergroupID = value
		case "custom_emoji_sticker_set_id":
			value, err := b.Long()
			if err != nil {
				return fmt.Errorf("unable to decode setSupergroupCustomEmojiStickerSet#4f3552af: field custom_emoji_sticker_set_id: %w", err)
			}
			s.CustomEmojiStickerSetID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetSupergroupID returns value of SupergroupID field.
func (s *SetSupergroupCustomEmojiStickerSetRequest) GetSupergroupID() (value int64) {
	if s == nil {
		return
	}
	return s.SupergroupID
}

// GetCustomEmojiStickerSetID returns value of CustomEmojiStickerSetID field.
func (s *SetSupergroupCustomEmojiStickerSetRequest) GetCustomEmojiStickerSetID() (value int64) {
	if s == nil {
		return
	}
	return s.CustomEmojiStickerSetID
}

// SetSupergroupCustomEmojiStickerSet invokes method setSupergroupCustomEmojiStickerSet#4f3552af returning error if any.
func (c *Client) SetSupergroupCustomEmojiStickerSet(ctx context.Context, request *SetSupergroupCustomEmojiStickerSetRequest) error {
	var ok Ok

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