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

// PaidReactionTypeRegular represents TL type `paidReactionTypeRegular#b885da7b`.
type PaidReactionTypeRegular struct {
}

// PaidReactionTypeRegularTypeID is TL type id of PaidReactionTypeRegular.
const PaidReactionTypeRegularTypeID = 0xb885da7b

// construct implements constructor of PaidReactionTypeClass.
func (p PaidReactionTypeRegular) construct() PaidReactionTypeClass { return &p }

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

	_ PaidReactionTypeClass = &PaidReactionTypeRegular{}
)

func (p *PaidReactionTypeRegular) Zero() bool {
	if p == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PaidReactionTypeRegular) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "paidReactionTypeRegular",
		ID:   PaidReactionTypeRegularTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (p *PaidReactionTypeRegular) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode paidReactionTypeRegular#b885da7b as nil")
	}
	b.PutID(PaidReactionTypeRegularTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PaidReactionTypeRegular) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode paidReactionTypeRegular#b885da7b as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (p *PaidReactionTypeRegular) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode paidReactionTypeRegular#b885da7b to nil")
	}
	if err := b.ConsumeID(PaidReactionTypeRegularTypeID); err != nil {
		return fmt.Errorf("unable to decode paidReactionTypeRegular#b885da7b: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *PaidReactionTypeRegular) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode paidReactionTypeRegular#b885da7b to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PaidReactionTypeRegular) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode paidReactionTypeRegular#b885da7b as nil")
	}
	b.ObjStart()
	b.PutID("paidReactionTypeRegular")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (p *PaidReactionTypeRegular) DecodeTDLibJSON(b tdjson.Decoder) error {
	if p == nil {
		return fmt.Errorf("can't decode paidReactionTypeRegular#b885da7b to nil")
	}

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

// PaidReactionTypeAnonymous represents TL type `paidReactionTypeAnonymous#2dac88d`.
type PaidReactionTypeAnonymous struct {
}

// PaidReactionTypeAnonymousTypeID is TL type id of PaidReactionTypeAnonymous.
const PaidReactionTypeAnonymousTypeID = 0x2dac88d

// construct implements constructor of PaidReactionTypeClass.
func (p PaidReactionTypeAnonymous) construct() PaidReactionTypeClass { return &p }

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

	_ PaidReactionTypeClass = &PaidReactionTypeAnonymous{}
)

func (p *PaidReactionTypeAnonymous) Zero() bool {
	if p == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PaidReactionTypeAnonymous) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "paidReactionTypeAnonymous",
		ID:   PaidReactionTypeAnonymousTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (p *PaidReactionTypeAnonymous) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode paidReactionTypeAnonymous#2dac88d as nil")
	}
	b.PutID(PaidReactionTypeAnonymousTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PaidReactionTypeAnonymous) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode paidReactionTypeAnonymous#2dac88d as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (p *PaidReactionTypeAnonymous) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode paidReactionTypeAnonymous#2dac88d to nil")
	}
	if err := b.ConsumeID(PaidReactionTypeAnonymousTypeID); err != nil {
		return fmt.Errorf("unable to decode paidReactionTypeAnonymous#2dac88d: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *PaidReactionTypeAnonymous) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode paidReactionTypeAnonymous#2dac88d to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PaidReactionTypeAnonymous) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode paidReactionTypeAnonymous#2dac88d as nil")
	}
	b.ObjStart()
	b.PutID("paidReactionTypeAnonymous")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (p *PaidReactionTypeAnonymous) DecodeTDLibJSON(b tdjson.Decoder) error {
	if p == nil {
		return fmt.Errorf("can't decode paidReactionTypeAnonymous#2dac88d to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("paidReactionTypeAnonymous"); err != nil {
				return fmt.Errorf("unable to decode paidReactionTypeAnonymous#2dac88d: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// PaidReactionTypeChat represents TL type `paidReactionTypeChat#d7b86264`.
type PaidReactionTypeChat struct {
	// Identifier of the chat
	ChatID int64
}

// PaidReactionTypeChatTypeID is TL type id of PaidReactionTypeChat.
const PaidReactionTypeChatTypeID = 0xd7b86264

// construct implements constructor of PaidReactionTypeClass.
func (p PaidReactionTypeChat) construct() PaidReactionTypeClass { return &p }

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

	_ PaidReactionTypeClass = &PaidReactionTypeChat{}
)

func (p *PaidReactionTypeChat) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.ChatID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *PaidReactionTypeChat) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "paidReactionTypeChat",
		ID:   PaidReactionTypeChatTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *PaidReactionTypeChat) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode paidReactionTypeChat#d7b86264 as nil")
	}
	b.PutID(PaidReactionTypeChatTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PaidReactionTypeChat) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode paidReactionTypeChat#d7b86264 as nil")
	}
	b.PutInt53(p.ChatID)
	return nil
}

// Decode implements bin.Decoder.
func (p *PaidReactionTypeChat) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode paidReactionTypeChat#d7b86264 to nil")
	}
	if err := b.ConsumeID(PaidReactionTypeChatTypeID); err != nil {
		return fmt.Errorf("unable to decode paidReactionTypeChat#d7b86264: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *PaidReactionTypeChat) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode paidReactionTypeChat#d7b86264 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode paidReactionTypeChat#d7b86264: field chat_id: %w", err)
		}
		p.ChatID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PaidReactionTypeChat) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode paidReactionTypeChat#d7b86264 as nil")
	}
	b.ObjStart()
	b.PutID("paidReactionTypeChat")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(p.ChatID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (p *PaidReactionTypeChat) DecodeTDLibJSON(b tdjson.Decoder) error {
	if p == nil {
		return fmt.Errorf("can't decode paidReactionTypeChat#d7b86264 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("paidReactionTypeChat"); err != nil {
				return fmt.Errorf("unable to decode paidReactionTypeChat#d7b86264: %w", err)
			}
		case "chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode paidReactionTypeChat#d7b86264: field chat_id: %w", err)
			}
			p.ChatID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetChatID returns value of ChatID field.
func (p *PaidReactionTypeChat) GetChatID() (value int64) {
	if p == nil {
		return
	}
	return p.ChatID
}

// PaidReactionTypeClassName is schema name of PaidReactionTypeClass.
const PaidReactionTypeClassName = "PaidReactionType"

// PaidReactionTypeClass represents PaidReactionType generic type.
//
// Example:
//
//	g, err := tdapi.DecodePaidReactionType(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.PaidReactionTypeRegular: // paidReactionTypeRegular#b885da7b
//	case *tdapi.PaidReactionTypeAnonymous: // paidReactionTypeAnonymous#2dac88d
//	case *tdapi.PaidReactionTypeChat: // paidReactionTypeChat#d7b86264
//	default: panic(v)
//	}
type PaidReactionTypeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() PaidReactionTypeClass

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

// DecodePaidReactionType implements binary de-serialization for PaidReactionTypeClass.
func DecodePaidReactionType(buf *bin.Buffer) (PaidReactionTypeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case PaidReactionTypeRegularTypeID:
		// Decoding paidReactionTypeRegular#b885da7b.
		v := PaidReactionTypeRegular{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PaidReactionTypeClass: %w", err)
		}
		return &v, nil
	case PaidReactionTypeAnonymousTypeID:
		// Decoding paidReactionTypeAnonymous#2dac88d.
		v := PaidReactionTypeAnonymous{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PaidReactionTypeClass: %w", err)
		}
		return &v, nil
	case PaidReactionTypeChatTypeID:
		// Decoding paidReactionTypeChat#d7b86264.
		v := PaidReactionTypeChat{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PaidReactionTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode PaidReactionTypeClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONPaidReactionType implements binary de-serialization for PaidReactionTypeClass.
func DecodeTDLibJSONPaidReactionType(buf tdjson.Decoder) (PaidReactionTypeClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "paidReactionTypeRegular":
		// Decoding paidReactionTypeRegular#b885da7b.
		v := PaidReactionTypeRegular{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PaidReactionTypeClass: %w", err)
		}
		return &v, nil
	case "paidReactionTypeAnonymous":
		// Decoding paidReactionTypeAnonymous#2dac88d.
		v := PaidReactionTypeAnonymous{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PaidReactionTypeClass: %w", err)
		}
		return &v, nil
	case "paidReactionTypeChat":
		// Decoding paidReactionTypeChat#d7b86264.
		v := PaidReactionTypeChat{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PaidReactionTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode PaidReactionTypeClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// PaidReactionType boxes the PaidReactionTypeClass providing a helper.
type PaidReactionTypeBox struct {
	PaidReactionType PaidReactionTypeClass
}

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

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

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

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