// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// StarGiftAttributeIDModel represents TL type `starGiftAttributeIdModel#48aaae3c`.
// The ID of a model of a collectible gift »¹.
//
// Links:
//  1. https://core.telegram.org/api/gifts#collectible-gifts
//
// See https://core.telegram.org/constructor/starGiftAttributeIdModel for reference.
type StarGiftAttributeIDModel struct {
	// The sticker¹ representing the upgraded gift
	//
	// Links:
	//  1) https://core.telegram.org/api/stickers
	DocumentID int64
}

// StarGiftAttributeIDModelTypeID is TL type id of StarGiftAttributeIDModel.
const StarGiftAttributeIDModelTypeID = 0x48aaae3c

// construct implements constructor of StarGiftAttributeIDClass.
func (s StarGiftAttributeIDModel) construct() StarGiftAttributeIDClass { return &s }

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

	_ StarGiftAttributeIDClass = &StarGiftAttributeIDModel{}
)

func (s *StarGiftAttributeIDModel) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.DocumentID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills StarGiftAttributeIDModel from given interface.
func (s *StarGiftAttributeIDModel) FillFrom(from interface {
	GetDocumentID() (value int64)
}) {
	s.DocumentID = from.GetDocumentID()
}

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

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

// TypeInfo returns info about TL type.
func (s *StarGiftAttributeIDModel) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "starGiftAttributeIdModel",
		ID:   StarGiftAttributeIDModelTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "DocumentID",
			SchemaName: "document_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StarGiftAttributeIDModel) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode starGiftAttributeIdModel#48aaae3c as nil")
	}
	b.PutID(StarGiftAttributeIDModelTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StarGiftAttributeIDModel) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode starGiftAttributeIdModel#48aaae3c as nil")
	}
	b.PutLong(s.DocumentID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StarGiftAttributeIDModel) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode starGiftAttributeIdModel#48aaae3c to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode starGiftAttributeIdModel#48aaae3c: field document_id: %w", err)
		}
		s.DocumentID = value
	}
	return nil
}

// GetDocumentID returns value of DocumentID field.
func (s *StarGiftAttributeIDModel) GetDocumentID() (value int64) {
	if s == nil {
		return
	}
	return s.DocumentID
}

// StarGiftAttributeIDPattern represents TL type `starGiftAttributeIdPattern#4a162433`.
// The ID of a pattern of a collectible gift »¹.
//
// Links:
//  1. https://core.telegram.org/api/gifts#collectible-gifts
//
// See https://core.telegram.org/constructor/starGiftAttributeIdPattern for reference.
type StarGiftAttributeIDPattern struct {
	// The sticker¹ representing the symbol
	//
	// Links:
	//  1) https://core.telegram.org/api/stickers
	DocumentID int64
}

// StarGiftAttributeIDPatternTypeID is TL type id of StarGiftAttributeIDPattern.
const StarGiftAttributeIDPatternTypeID = 0x4a162433

// construct implements constructor of StarGiftAttributeIDClass.
func (s StarGiftAttributeIDPattern) construct() StarGiftAttributeIDClass { return &s }

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

	_ StarGiftAttributeIDClass = &StarGiftAttributeIDPattern{}
)

func (s *StarGiftAttributeIDPattern) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.DocumentID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills StarGiftAttributeIDPattern from given interface.
func (s *StarGiftAttributeIDPattern) FillFrom(from interface {
	GetDocumentID() (value int64)
}) {
	s.DocumentID = from.GetDocumentID()
}

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

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

// TypeInfo returns info about TL type.
func (s *StarGiftAttributeIDPattern) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "starGiftAttributeIdPattern",
		ID:   StarGiftAttributeIDPatternTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "DocumentID",
			SchemaName: "document_id",
		},
	}
	return typ
}

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

// EncodeBare implements bin.BareEncoder.
func (s *StarGiftAttributeIDPattern) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode starGiftAttributeIdPattern#4a162433 as nil")
	}
	b.PutLong(s.DocumentID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StarGiftAttributeIDPattern) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode starGiftAttributeIdPattern#4a162433 to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode starGiftAttributeIdPattern#4a162433: field document_id: %w", err)
		}
		s.DocumentID = value
	}
	return nil
}

// GetDocumentID returns value of DocumentID field.
func (s *StarGiftAttributeIDPattern) GetDocumentID() (value int64) {
	if s == nil {
		return
	}
	return s.DocumentID
}

// StarGiftAttributeIDBackdrop represents TL type `starGiftAttributeIdBackdrop#1f01c757`.
// The ID of a backdrop of a collectible gift »¹.
//
// Links:
//  1. https://core.telegram.org/api/gifts#collectible-gifts
//
// See https://core.telegram.org/constructor/starGiftAttributeIdBackdrop for reference.
type StarGiftAttributeIDBackdrop struct {
	// Unique ID of the backdrop.
	BackdropID int
}

// StarGiftAttributeIDBackdropTypeID is TL type id of StarGiftAttributeIDBackdrop.
const StarGiftAttributeIDBackdropTypeID = 0x1f01c757

// construct implements constructor of StarGiftAttributeIDClass.
func (s StarGiftAttributeIDBackdrop) construct() StarGiftAttributeIDClass { return &s }

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

	_ StarGiftAttributeIDClass = &StarGiftAttributeIDBackdrop{}
)

func (s *StarGiftAttributeIDBackdrop) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.BackdropID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills StarGiftAttributeIDBackdrop from given interface.
func (s *StarGiftAttributeIDBackdrop) FillFrom(from interface {
	GetBackdropID() (value int)
}) {
	s.BackdropID = from.GetBackdropID()
}

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

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

// TypeInfo returns info about TL type.
func (s *StarGiftAttributeIDBackdrop) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "starGiftAttributeIdBackdrop",
		ID:   StarGiftAttributeIDBackdropTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BackdropID",
			SchemaName: "backdrop_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StarGiftAttributeIDBackdrop) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode starGiftAttributeIdBackdrop#1f01c757 as nil")
	}
	b.PutID(StarGiftAttributeIDBackdropTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StarGiftAttributeIDBackdrop) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode starGiftAttributeIdBackdrop#1f01c757 as nil")
	}
	b.PutInt(s.BackdropID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StarGiftAttributeIDBackdrop) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode starGiftAttributeIdBackdrop#1f01c757 to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode starGiftAttributeIdBackdrop#1f01c757: field backdrop_id: %w", err)
		}
		s.BackdropID = value
	}
	return nil
}

// GetBackdropID returns value of BackdropID field.
func (s *StarGiftAttributeIDBackdrop) GetBackdropID() (value int) {
	if s == nil {
		return
	}
	return s.BackdropID
}

// StarGiftAttributeIDClassName is schema name of StarGiftAttributeIDClass.
const StarGiftAttributeIDClassName = "StarGiftAttributeId"

// StarGiftAttributeIDClass represents StarGiftAttributeId generic type.
//
// See https://core.telegram.org/type/StarGiftAttributeId for reference.
//
// Example:
//
//	g, err := tg.DecodeStarGiftAttributeID(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.StarGiftAttributeIDModel: // starGiftAttributeIdModel#48aaae3c
//	case *tg.StarGiftAttributeIDPattern: // starGiftAttributeIdPattern#4a162433
//	case *tg.StarGiftAttributeIDBackdrop: // starGiftAttributeIdBackdrop#1f01c757
//	default: panic(v)
//	}
type StarGiftAttributeIDClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() StarGiftAttributeIDClass

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

// DecodeStarGiftAttributeID implements binary de-serialization for StarGiftAttributeIDClass.
func DecodeStarGiftAttributeID(buf *bin.Buffer) (StarGiftAttributeIDClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case StarGiftAttributeIDModelTypeID:
		// Decoding starGiftAttributeIdModel#48aaae3c.
		v := StarGiftAttributeIDModel{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StarGiftAttributeIDClass: %w", err)
		}
		return &v, nil
	case StarGiftAttributeIDPatternTypeID:
		// Decoding starGiftAttributeIdPattern#4a162433.
		v := StarGiftAttributeIDPattern{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StarGiftAttributeIDClass: %w", err)
		}
		return &v, nil
	case StarGiftAttributeIDBackdropTypeID:
		// Decoding starGiftAttributeIdBackdrop#1f01c757.
		v := StarGiftAttributeIDBackdrop{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StarGiftAttributeIDClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode StarGiftAttributeIDClass: %w", bin.NewUnexpectedID(id))
	}
}

// StarGiftAttributeID boxes the StarGiftAttributeIDClass providing a helper.
type StarGiftAttributeIDBox struct {
	StarGiftAttributeId StarGiftAttributeIDClass
}

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

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