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

// StarGiftUpgradePrice represents TL type `starGiftUpgradePrice#99ea331d`.
//
// See https://core.telegram.org/constructor/starGiftUpgradePrice for reference.
type StarGiftUpgradePrice struct {
	// Date field of StarGiftUpgradePrice.
	Date int
	// UpgradeStars field of StarGiftUpgradePrice.
	UpgradeStars int64
}

// StarGiftUpgradePriceTypeID is TL type id of StarGiftUpgradePrice.
const StarGiftUpgradePriceTypeID = 0x99ea331d

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

func (s *StarGiftUpgradePrice) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Date == 0) {
		return false
	}
	if !(s.UpgradeStars == 0) {
		return false
	}

	return true
}

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

// FillFrom fills StarGiftUpgradePrice from given interface.
func (s *StarGiftUpgradePrice) FillFrom(from interface {
	GetDate() (value int)
	GetUpgradeStars() (value int64)
}) {
	s.Date = from.GetDate()
	s.UpgradeStars = from.GetUpgradeStars()
}

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

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

// TypeInfo returns info about TL type.
func (s *StarGiftUpgradePrice) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "starGiftUpgradePrice",
		ID:   StarGiftUpgradePriceTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Date",
			SchemaName: "date",
		},
		{
			Name:       "UpgradeStars",
			SchemaName: "upgrade_stars",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StarGiftUpgradePrice) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode starGiftUpgradePrice#99ea331d as nil")
	}
	b.PutID(StarGiftUpgradePriceTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StarGiftUpgradePrice) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode starGiftUpgradePrice#99ea331d as nil")
	}
	b.PutInt(s.Date)
	b.PutLong(s.UpgradeStars)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StarGiftUpgradePrice) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode starGiftUpgradePrice#99ea331d to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode starGiftUpgradePrice#99ea331d: field date: %w", err)
		}
		s.Date = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode starGiftUpgradePrice#99ea331d: field upgrade_stars: %w", err)
		}
		s.UpgradeStars = value
	}
	return nil
}

// GetDate returns value of Date field.
func (s *StarGiftUpgradePrice) GetDate() (value int) {
	if s == nil {
		return
	}
	return s.Date
}

// GetUpgradeStars returns value of UpgradeStars field.
func (s *StarGiftUpgradePrice) GetUpgradeStars() (value int64) {
	if s == nil {
		return
	}
	return s.UpgradeStars
}
