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

// ChatPhotoStickerTypeRegularOrMask represents TL type `chatPhotoStickerTypeRegularOrMask#e741599c`.
type ChatPhotoStickerTypeRegularOrMask struct {
	// Sticker set identifier
	StickerSetID int64
	// Identifier of the sticker in the set
	StickerID int64
}

// ChatPhotoStickerTypeRegularOrMaskTypeID is TL type id of ChatPhotoStickerTypeRegularOrMask.
const ChatPhotoStickerTypeRegularOrMaskTypeID = 0xe741599c

// construct implements constructor of ChatPhotoStickerTypeClass.
func (c ChatPhotoStickerTypeRegularOrMask) construct() ChatPhotoStickerTypeClass { return &c }

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

	_ ChatPhotoStickerTypeClass = &ChatPhotoStickerTypeRegularOrMask{}
)

func (c *ChatPhotoStickerTypeRegularOrMask) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.StickerSetID == 0) {
		return false
	}
	if !(c.StickerID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *ChatPhotoStickerTypeRegularOrMask) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "chatPhotoStickerTypeRegularOrMask",
		ID:   ChatPhotoStickerTypeRegularOrMaskTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "StickerSetID",
			SchemaName: "sticker_set_id",
		},
		{
			Name:       "StickerID",
			SchemaName: "sticker_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *ChatPhotoStickerTypeRegularOrMask) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode chatPhotoStickerTypeRegularOrMask#e741599c as nil")
	}
	b.PutID(ChatPhotoStickerTypeRegularOrMaskTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *ChatPhotoStickerTypeRegularOrMask) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode chatPhotoStickerTypeRegularOrMask#e741599c as nil")
	}
	b.PutLong(c.StickerSetID)
	b.PutLong(c.StickerID)
	return nil
}

// Decode implements bin.Decoder.
func (c *ChatPhotoStickerTypeRegularOrMask) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode chatPhotoStickerTypeRegularOrMask#e741599c to nil")
	}
	if err := b.ConsumeID(ChatPhotoStickerTypeRegularOrMaskTypeID); err != nil {
		return fmt.Errorf("unable to decode chatPhotoStickerTypeRegularOrMask#e741599c: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *ChatPhotoStickerTypeRegularOrMask) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode chatPhotoStickerTypeRegularOrMask#e741599c to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode chatPhotoStickerTypeRegularOrMask#e741599c: field sticker_set_id: %w", err)
		}
		c.StickerSetID = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode chatPhotoStickerTypeRegularOrMask#e741599c: field sticker_id: %w", err)
		}
		c.StickerID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *ChatPhotoStickerTypeRegularOrMask) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode chatPhotoStickerTypeRegularOrMask#e741599c as nil")
	}
	b.ObjStart()
	b.PutID("chatPhotoStickerTypeRegularOrMask")
	b.Comma()
	b.FieldStart("sticker_set_id")
	b.PutLong(c.StickerSetID)
	b.Comma()
	b.FieldStart("sticker_id")
	b.PutLong(c.StickerID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *ChatPhotoStickerTypeRegularOrMask) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode chatPhotoStickerTypeRegularOrMask#e741599c to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("chatPhotoStickerTypeRegularOrMask"); err != nil {
				return fmt.Errorf("unable to decode chatPhotoStickerTypeRegularOrMask#e741599c: %w", err)
			}
		case "sticker_set_id":
			value, err := b.Long()
			if err != nil {
				return fmt.Errorf("unable to decode chatPhotoStickerTypeRegularOrMask#e741599c: field sticker_set_id: %w", err)
			}
			c.StickerSetID = value
		case "sticker_id":
			value, err := b.Long()
			if err != nil {
				return fmt.Errorf("unable to decode chatPhotoStickerTypeRegularOrMask#e741599c: field sticker_id: %w", err)
			}
			c.StickerID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetStickerSetID returns value of StickerSetID field.
func (c *ChatPhotoStickerTypeRegularOrMask) GetStickerSetID() (value int64) {
	if c == nil {
		return
	}
	return c.StickerSetID
}

// GetStickerID returns value of StickerID field.
func (c *ChatPhotoStickerTypeRegularOrMask) GetStickerID() (value int64) {
	if c == nil {
		return
	}
	return c.StickerID
}

// ChatPhotoStickerTypeCustomEmoji represents TL type `chatPhotoStickerTypeCustomEmoji#f021bad1`.
type ChatPhotoStickerTypeCustomEmoji struct {
	// Identifier of the custom emoji
	CustomEmojiID int64
}

// ChatPhotoStickerTypeCustomEmojiTypeID is TL type id of ChatPhotoStickerTypeCustomEmoji.
const ChatPhotoStickerTypeCustomEmojiTypeID = 0xf021bad1

// construct implements constructor of ChatPhotoStickerTypeClass.
func (c ChatPhotoStickerTypeCustomEmoji) construct() ChatPhotoStickerTypeClass { return &c }

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

	_ ChatPhotoStickerTypeClass = &ChatPhotoStickerTypeCustomEmoji{}
)

func (c *ChatPhotoStickerTypeCustomEmoji) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.CustomEmojiID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *ChatPhotoStickerTypeCustomEmoji) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "chatPhotoStickerTypeCustomEmoji",
		ID:   ChatPhotoStickerTypeCustomEmojiTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "CustomEmojiID",
			SchemaName: "custom_emoji_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *ChatPhotoStickerTypeCustomEmoji) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode chatPhotoStickerTypeCustomEmoji#f021bad1 as nil")
	}
	b.PutID(ChatPhotoStickerTypeCustomEmojiTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *ChatPhotoStickerTypeCustomEmoji) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode chatPhotoStickerTypeCustomEmoji#f021bad1 as nil")
	}
	b.PutLong(c.CustomEmojiID)
	return nil
}

// Decode implements bin.Decoder.
func (c *ChatPhotoStickerTypeCustomEmoji) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode chatPhotoStickerTypeCustomEmoji#f021bad1 to nil")
	}
	if err := b.ConsumeID(ChatPhotoStickerTypeCustomEmojiTypeID); err != nil {
		return fmt.Errorf("unable to decode chatPhotoStickerTypeCustomEmoji#f021bad1: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *ChatPhotoStickerTypeCustomEmoji) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode chatPhotoStickerTypeCustomEmoji#f021bad1 to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode chatPhotoStickerTypeCustomEmoji#f021bad1: field custom_emoji_id: %w", err)
		}
		c.CustomEmojiID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *ChatPhotoStickerTypeCustomEmoji) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode chatPhotoStickerTypeCustomEmoji#f021bad1 as nil")
	}
	b.ObjStart()
	b.PutID("chatPhotoStickerTypeCustomEmoji")
	b.Comma()
	b.FieldStart("custom_emoji_id")
	b.PutLong(c.CustomEmojiID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *ChatPhotoStickerTypeCustomEmoji) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode chatPhotoStickerTypeCustomEmoji#f021bad1 to nil")
	}

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

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

// ChatPhotoStickerTypeClassName is schema name of ChatPhotoStickerTypeClass.
const ChatPhotoStickerTypeClassName = "ChatPhotoStickerType"

// ChatPhotoStickerTypeClass represents ChatPhotoStickerType generic type.
//
// Example:
//
//	g, err := tdapi.DecodeChatPhotoStickerType(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.ChatPhotoStickerTypeRegularOrMask: // chatPhotoStickerTypeRegularOrMask#e741599c
//	case *tdapi.ChatPhotoStickerTypeCustomEmoji: // chatPhotoStickerTypeCustomEmoji#f021bad1
//	default: panic(v)
//	}
type ChatPhotoStickerTypeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() ChatPhotoStickerTypeClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	EncodeTDLibJSON(b tdjson.Encoder) error
	DecodeTDLibJSON(b tdjson.Decoder) error
}

// DecodeChatPhotoStickerType implements binary de-serialization for ChatPhotoStickerTypeClass.
func DecodeChatPhotoStickerType(buf *bin.Buffer) (ChatPhotoStickerTypeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case ChatPhotoStickerTypeRegularOrMaskTypeID:
		// Decoding chatPhotoStickerTypeRegularOrMask#e741599c.
		v := ChatPhotoStickerTypeRegularOrMask{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode ChatPhotoStickerTypeClass: %w", err)
		}
		return &v, nil
	case ChatPhotoStickerTypeCustomEmojiTypeID:
		// Decoding chatPhotoStickerTypeCustomEmoji#f021bad1.
		v := ChatPhotoStickerTypeCustomEmoji{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode ChatPhotoStickerTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode ChatPhotoStickerTypeClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONChatPhotoStickerType implements binary de-serialization for ChatPhotoStickerTypeClass.
func DecodeTDLibJSONChatPhotoStickerType(buf tdjson.Decoder) (ChatPhotoStickerTypeClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "chatPhotoStickerTypeRegularOrMask":
		// Decoding chatPhotoStickerTypeRegularOrMask#e741599c.
		v := ChatPhotoStickerTypeRegularOrMask{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode ChatPhotoStickerTypeClass: %w", err)
		}
		return &v, nil
	case "chatPhotoStickerTypeCustomEmoji":
		// Decoding chatPhotoStickerTypeCustomEmoji#f021bad1.
		v := ChatPhotoStickerTypeCustomEmoji{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode ChatPhotoStickerTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode ChatPhotoStickerTypeClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// ChatPhotoStickerType boxes the ChatPhotoStickerTypeClass providing a helper.
type ChatPhotoStickerTypeBox struct {
	ChatPhotoStickerType ChatPhotoStickerTypeClass
}

// Decode implements bin.Decoder for ChatPhotoStickerTypeBox.
func (b *ChatPhotoStickerTypeBox) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("unable to decode ChatPhotoStickerTypeBox to nil")
	}
	v, err := DecodeChatPhotoStickerType(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.ChatPhotoStickerType = v
	return nil
}

// Encode implements bin.Encode for ChatPhotoStickerTypeBox.
func (b *ChatPhotoStickerTypeBox) Encode(buf *bin.Buffer) error {
	if b == nil || b.ChatPhotoStickerType == nil {
		return fmt.Errorf("unable to encode ChatPhotoStickerTypeClass as nil")
	}
	return b.ChatPhotoStickerType.Encode(buf)
}

// DecodeTDLibJSON implements bin.Decoder for ChatPhotoStickerTypeBox.
func (b *ChatPhotoStickerTypeBox) DecodeTDLibJSON(buf tdjson.Decoder) error {
	if b == nil {
		return fmt.Errorf("unable to decode ChatPhotoStickerTypeBox to nil")
	}
	v, err := DecodeTDLibJSONChatPhotoStickerType(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.ChatPhotoStickerType = v
	return nil
}

// EncodeTDLibJSON implements bin.Encode for ChatPhotoStickerTypeBox.
func (b *ChatPhotoStickerTypeBox) EncodeTDLibJSON(buf tdjson.Encoder) error {
	if b == nil || b.ChatPhotoStickerType == nil {
		return fmt.Errorf("unable to encode ChatPhotoStickerTypeClass as nil")
	}
	return b.ChatPhotoStickerType.EncodeTDLibJSON(buf)
}
