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

// StarGiftAuctionRound represents TL type `starGiftAuctionRound#3aae0528`.
//
// See https://core.telegram.org/constructor/starGiftAuctionRound for reference.
type StarGiftAuctionRound struct {
	// Num field of StarGiftAuctionRound.
	Num int
	// Duration field of StarGiftAuctionRound.
	Duration int
}

// StarGiftAuctionRoundTypeID is TL type id of StarGiftAuctionRound.
const StarGiftAuctionRoundTypeID = 0x3aae0528

// construct implements constructor of StarGiftAuctionRoundClass.
func (s StarGiftAuctionRound) construct() StarGiftAuctionRoundClass { return &s }

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

	_ StarGiftAuctionRoundClass = &StarGiftAuctionRound{}
)

func (s *StarGiftAuctionRound) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Num == 0) {
		return false
	}
	if !(s.Duration == 0) {
		return false
	}

	return true
}

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

// FillFrom fills StarGiftAuctionRound from given interface.
func (s *StarGiftAuctionRound) FillFrom(from interface {
	GetNum() (value int)
	GetDuration() (value int)
}) {
	s.Num = from.GetNum()
	s.Duration = from.GetDuration()
}

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

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

// TypeInfo returns info about TL type.
func (s *StarGiftAuctionRound) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "starGiftAuctionRound",
		ID:   StarGiftAuctionRoundTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Num",
			SchemaName: "num",
		},
		{
			Name:       "Duration",
			SchemaName: "duration",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StarGiftAuctionRound) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode starGiftAuctionRound#3aae0528 as nil")
	}
	b.PutID(StarGiftAuctionRoundTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StarGiftAuctionRound) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode starGiftAuctionRound#3aae0528 as nil")
	}
	b.PutInt(s.Num)
	b.PutInt(s.Duration)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StarGiftAuctionRound) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode starGiftAuctionRound#3aae0528 to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode starGiftAuctionRound#3aae0528: field num: %w", err)
		}
		s.Num = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode starGiftAuctionRound#3aae0528: field duration: %w", err)
		}
		s.Duration = value
	}
	return nil
}

// GetNum returns value of Num field.
func (s *StarGiftAuctionRound) GetNum() (value int) {
	if s == nil {
		return
	}
	return s.Num
}

// GetDuration returns value of Duration field.
func (s *StarGiftAuctionRound) GetDuration() (value int) {
	if s == nil {
		return
	}
	return s.Duration
}

// StarGiftAuctionRoundExtendable represents TL type `starGiftAuctionRoundExtendable#aa021e5`.
//
// See https://core.telegram.org/constructor/starGiftAuctionRoundExtendable for reference.
type StarGiftAuctionRoundExtendable struct {
	// Num field of StarGiftAuctionRoundExtendable.
	Num int
	// Duration field of StarGiftAuctionRoundExtendable.
	Duration int
	// ExtendTop field of StarGiftAuctionRoundExtendable.
	ExtendTop int
	// ExtendWindow field of StarGiftAuctionRoundExtendable.
	ExtendWindow int
}

// StarGiftAuctionRoundExtendableTypeID is TL type id of StarGiftAuctionRoundExtendable.
const StarGiftAuctionRoundExtendableTypeID = 0xaa021e5

// construct implements constructor of StarGiftAuctionRoundClass.
func (s StarGiftAuctionRoundExtendable) construct() StarGiftAuctionRoundClass { return &s }

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

	_ StarGiftAuctionRoundClass = &StarGiftAuctionRoundExtendable{}
)

func (s *StarGiftAuctionRoundExtendable) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Num == 0) {
		return false
	}
	if !(s.Duration == 0) {
		return false
	}
	if !(s.ExtendTop == 0) {
		return false
	}
	if !(s.ExtendWindow == 0) {
		return false
	}

	return true
}

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

// FillFrom fills StarGiftAuctionRoundExtendable from given interface.
func (s *StarGiftAuctionRoundExtendable) FillFrom(from interface {
	GetNum() (value int)
	GetDuration() (value int)
	GetExtendTop() (value int)
	GetExtendWindow() (value int)
}) {
	s.Num = from.GetNum()
	s.Duration = from.GetDuration()
	s.ExtendTop = from.GetExtendTop()
	s.ExtendWindow = from.GetExtendWindow()
}

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

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

// TypeInfo returns info about TL type.
func (s *StarGiftAuctionRoundExtendable) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "starGiftAuctionRoundExtendable",
		ID:   StarGiftAuctionRoundExtendableTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Num",
			SchemaName: "num",
		},
		{
			Name:       "Duration",
			SchemaName: "duration",
		},
		{
			Name:       "ExtendTop",
			SchemaName: "extend_top",
		},
		{
			Name:       "ExtendWindow",
			SchemaName: "extend_window",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StarGiftAuctionRoundExtendable) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode starGiftAuctionRoundExtendable#aa021e5 as nil")
	}
	b.PutID(StarGiftAuctionRoundExtendableTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StarGiftAuctionRoundExtendable) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode starGiftAuctionRoundExtendable#aa021e5 as nil")
	}
	b.PutInt(s.Num)
	b.PutInt(s.Duration)
	b.PutInt(s.ExtendTop)
	b.PutInt(s.ExtendWindow)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StarGiftAuctionRoundExtendable) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode starGiftAuctionRoundExtendable#aa021e5 to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode starGiftAuctionRoundExtendable#aa021e5: field num: %w", err)
		}
		s.Num = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode starGiftAuctionRoundExtendable#aa021e5: field duration: %w", err)
		}
		s.Duration = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode starGiftAuctionRoundExtendable#aa021e5: field extend_top: %w", err)
		}
		s.ExtendTop = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode starGiftAuctionRoundExtendable#aa021e5: field extend_window: %w", err)
		}
		s.ExtendWindow = value
	}
	return nil
}

// GetNum returns value of Num field.
func (s *StarGiftAuctionRoundExtendable) GetNum() (value int) {
	if s == nil {
		return
	}
	return s.Num
}

// GetDuration returns value of Duration field.
func (s *StarGiftAuctionRoundExtendable) GetDuration() (value int) {
	if s == nil {
		return
	}
	return s.Duration
}

// GetExtendTop returns value of ExtendTop field.
func (s *StarGiftAuctionRoundExtendable) GetExtendTop() (value int) {
	if s == nil {
		return
	}
	return s.ExtendTop
}

// GetExtendWindow returns value of ExtendWindow field.
func (s *StarGiftAuctionRoundExtendable) GetExtendWindow() (value int) {
	if s == nil {
		return
	}
	return s.ExtendWindow
}

// StarGiftAuctionRoundClassName is schema name of StarGiftAuctionRoundClass.
const StarGiftAuctionRoundClassName = "StarGiftAuctionRound"

// StarGiftAuctionRoundClass represents StarGiftAuctionRound generic type.
//
// See https://core.telegram.org/type/StarGiftAuctionRound for reference.
//
// Example:
//
//	g, err := tg.DecodeStarGiftAuctionRound(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.StarGiftAuctionRound: // starGiftAuctionRound#3aae0528
//	case *tg.StarGiftAuctionRoundExtendable: // starGiftAuctionRoundExtendable#aa021e5
//	default: panic(v)
//	}
type StarGiftAuctionRoundClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() StarGiftAuctionRoundClass

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

	// Num field of StarGiftAuctionRound.
	GetNum() (value int)

	// Duration field of StarGiftAuctionRound.
	GetDuration() (value int)
}

// DecodeStarGiftAuctionRound implements binary de-serialization for StarGiftAuctionRoundClass.
func DecodeStarGiftAuctionRound(buf *bin.Buffer) (StarGiftAuctionRoundClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case StarGiftAuctionRoundTypeID:
		// Decoding starGiftAuctionRound#3aae0528.
		v := StarGiftAuctionRound{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StarGiftAuctionRoundClass: %w", err)
		}
		return &v, nil
	case StarGiftAuctionRoundExtendableTypeID:
		// Decoding starGiftAuctionRoundExtendable#aa021e5.
		v := StarGiftAuctionRoundExtendable{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StarGiftAuctionRoundClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode StarGiftAuctionRoundClass: %w", bin.NewUnexpectedID(id))
	}
}

// StarGiftAuctionRound boxes the StarGiftAuctionRoundClass providing a helper.
type StarGiftAuctionRoundBox struct {
	StarGiftAuctionRound StarGiftAuctionRoundClass
}

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

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