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

// StorePaymentPurposePremiumSubscription represents TL type `storePaymentPurposePremiumSubscription#4b558114`.
type StorePaymentPurposePremiumSubscription struct {
	// Pass true if this is a restore of a Telegram Premium purchase; only for App Store
	IsRestore bool
	// Pass true if this is an upgrade from a monthly subscription to early subscription;
	// only for App Store
	IsUpgrade bool
}

// StorePaymentPurposePremiumSubscriptionTypeID is TL type id of StorePaymentPurposePremiumSubscription.
const StorePaymentPurposePremiumSubscriptionTypeID = 0x4b558114

// construct implements constructor of StorePaymentPurposeClass.
func (s StorePaymentPurposePremiumSubscription) construct() StorePaymentPurposeClass { return &s }

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

	_ StorePaymentPurposeClass = &StorePaymentPurposePremiumSubscription{}
)

func (s *StorePaymentPurposePremiumSubscription) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.IsRestore == false) {
		return false
	}
	if !(s.IsUpgrade == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *StorePaymentPurposePremiumSubscription) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "storePaymentPurposePremiumSubscription",
		ID:   StorePaymentPurposePremiumSubscriptionTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "IsRestore",
			SchemaName: "is_restore",
		},
		{
			Name:       "IsUpgrade",
			SchemaName: "is_upgrade",
		},
	}
	return typ
}

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

// EncodeBare implements bin.BareEncoder.
func (s *StorePaymentPurposePremiumSubscription) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposePremiumSubscription#4b558114 as nil")
	}
	b.PutBool(s.IsRestore)
	b.PutBool(s.IsUpgrade)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StorePaymentPurposePremiumSubscription) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode storePaymentPurposePremiumSubscription#4b558114 to nil")
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposePremiumSubscription#4b558114: field is_restore: %w", err)
		}
		s.IsRestore = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposePremiumSubscription#4b558114: field is_upgrade: %w", err)
		}
		s.IsUpgrade = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *StorePaymentPurposePremiumSubscription) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposePremiumSubscription#4b558114 as nil")
	}
	b.ObjStart()
	b.PutID("storePaymentPurposePremiumSubscription")
	b.Comma()
	b.FieldStart("is_restore")
	b.PutBool(s.IsRestore)
	b.Comma()
	b.FieldStart("is_upgrade")
	b.PutBool(s.IsUpgrade)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *StorePaymentPurposePremiumSubscription) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode storePaymentPurposePremiumSubscription#4b558114 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("storePaymentPurposePremiumSubscription"); err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumSubscription#4b558114: %w", err)
			}
		case "is_restore":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumSubscription#4b558114: field is_restore: %w", err)
			}
			s.IsRestore = value
		case "is_upgrade":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumSubscription#4b558114: field is_upgrade: %w", err)
			}
			s.IsUpgrade = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetIsRestore returns value of IsRestore field.
func (s *StorePaymentPurposePremiumSubscription) GetIsRestore() (value bool) {
	if s == nil {
		return
	}
	return s.IsRestore
}

// GetIsUpgrade returns value of IsUpgrade field.
func (s *StorePaymentPurposePremiumSubscription) GetIsUpgrade() (value bool) {
	if s == nil {
		return
	}
	return s.IsUpgrade
}

// StorePaymentPurposePremiumGift represents TL type `storePaymentPurposePremiumGift#fda53d95`.
type StorePaymentPurposePremiumGift struct {
	// ISO 4217 currency code of the payment currency
	Currency string
	// Paid amount, in the smallest units of the currency
	Amount int64
	// Identifiers of the user which will receive Telegram Premium
	UserID int64
	// Text to show along with the gift codes; 0-getOption("gift_text_length_max") characters
	// Only Bold, Italic, Underline, Strikethrough, Spoiler, and CustomEmoji entities are
	// allowed
	Text FormattedText
}

// StorePaymentPurposePremiumGiftTypeID is TL type id of StorePaymentPurposePremiumGift.
const StorePaymentPurposePremiumGiftTypeID = 0xfda53d95

// construct implements constructor of StorePaymentPurposeClass.
func (s StorePaymentPurposePremiumGift) construct() StorePaymentPurposeClass { return &s }

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

	_ StorePaymentPurposeClass = &StorePaymentPurposePremiumGift{}
)

func (s *StorePaymentPurposePremiumGift) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Currency == "") {
		return false
	}
	if !(s.Amount == 0) {
		return false
	}
	if !(s.UserID == 0) {
		return false
	}
	if !(s.Text.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *StorePaymentPurposePremiumGift) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "storePaymentPurposePremiumGift",
		ID:   StorePaymentPurposePremiumGiftTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Currency",
			SchemaName: "currency",
		},
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
		{
			Name:       "Text",
			SchemaName: "text",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StorePaymentPurposePremiumGift) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposePremiumGift#fda53d95 as nil")
	}
	b.PutID(StorePaymentPurposePremiumGiftTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StorePaymentPurposePremiumGift) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposePremiumGift#fda53d95 as nil")
	}
	b.PutString(s.Currency)
	b.PutInt53(s.Amount)
	b.PutInt53(s.UserID)
	if err := s.Text.Encode(b); err != nil {
		return fmt.Errorf("unable to encode storePaymentPurposePremiumGift#fda53d95: field text: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StorePaymentPurposePremiumGift) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode storePaymentPurposePremiumGift#fda53d95 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposePremiumGift#fda53d95: field currency: %w", err)
		}
		s.Currency = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposePremiumGift#fda53d95: field amount: %w", err)
		}
		s.Amount = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposePremiumGift#fda53d95: field user_id: %w", err)
		}
		s.UserID = value
	}
	{
		if err := s.Text.Decode(b); err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposePremiumGift#fda53d95: field text: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *StorePaymentPurposePremiumGift) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposePremiumGift#fda53d95 as nil")
	}
	b.ObjStart()
	b.PutID("storePaymentPurposePremiumGift")
	b.Comma()
	b.FieldStart("currency")
	b.PutString(s.Currency)
	b.Comma()
	b.FieldStart("amount")
	b.PutInt53(s.Amount)
	b.Comma()
	b.FieldStart("user_id")
	b.PutInt53(s.UserID)
	b.Comma()
	b.FieldStart("text")
	if err := s.Text.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode storePaymentPurposePremiumGift#fda53d95: field text: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *StorePaymentPurposePremiumGift) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode storePaymentPurposePremiumGift#fda53d95 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("storePaymentPurposePremiumGift"); err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumGift#fda53d95: %w", err)
			}
		case "currency":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumGift#fda53d95: field currency: %w", err)
			}
			s.Currency = value
		case "amount":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumGift#fda53d95: field amount: %w", err)
			}
			s.Amount = value
		case "user_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumGift#fda53d95: field user_id: %w", err)
			}
			s.UserID = value
		case "text":
			if err := s.Text.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumGift#fda53d95: field text: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetCurrency returns value of Currency field.
func (s *StorePaymentPurposePremiumGift) GetCurrency() (value string) {
	if s == nil {
		return
	}
	return s.Currency
}

// GetAmount returns value of Amount field.
func (s *StorePaymentPurposePremiumGift) GetAmount() (value int64) {
	if s == nil {
		return
	}
	return s.Amount
}

// GetUserID returns value of UserID field.
func (s *StorePaymentPurposePremiumGift) GetUserID() (value int64) {
	if s == nil {
		return
	}
	return s.UserID
}

// GetText returns value of Text field.
func (s *StorePaymentPurposePremiumGift) GetText() (value FormattedText) {
	if s == nil {
		return
	}
	return s.Text
}

// StorePaymentPurposePremiumGiftCodes represents TL type `storePaymentPurposePremiumGiftCodes#1277b01d`.
type StorePaymentPurposePremiumGiftCodes struct {
	// Identifier of the supergroup or channel chat, which will be automatically boosted by
	// the users for duration of the Premium subscription and which is administered by the
	// user
	BoostedChatID int64
	// ISO 4217 currency code of the payment currency
	Currency string
	// Paid amount, in the smallest units of the currency
	Amount int64
	// Identifiers of the users which can activate the gift codes
	UserIDs []int64
	// Text to show along with the gift codes; 0-getOption("gift_text_length_max") characters
	// Only Bold, Italic, Underline, Strikethrough, Spoiler, and CustomEmoji entities are
	// allowed
	Text FormattedText
}

// StorePaymentPurposePremiumGiftCodesTypeID is TL type id of StorePaymentPurposePremiumGiftCodes.
const StorePaymentPurposePremiumGiftCodesTypeID = 0x1277b01d

// construct implements constructor of StorePaymentPurposeClass.
func (s StorePaymentPurposePremiumGiftCodes) construct() StorePaymentPurposeClass { return &s }

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

	_ StorePaymentPurposeClass = &StorePaymentPurposePremiumGiftCodes{}
)

func (s *StorePaymentPurposePremiumGiftCodes) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.BoostedChatID == 0) {
		return false
	}
	if !(s.Currency == "") {
		return false
	}
	if !(s.Amount == 0) {
		return false
	}
	if !(s.UserIDs == nil) {
		return false
	}
	if !(s.Text.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *StorePaymentPurposePremiumGiftCodes) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "storePaymentPurposePremiumGiftCodes",
		ID:   StorePaymentPurposePremiumGiftCodesTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BoostedChatID",
			SchemaName: "boosted_chat_id",
		},
		{
			Name:       "Currency",
			SchemaName: "currency",
		},
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
		{
			Name:       "UserIDs",
			SchemaName: "user_ids",
		},
		{
			Name:       "Text",
			SchemaName: "text",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StorePaymentPurposePremiumGiftCodes) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposePremiumGiftCodes#1277b01d as nil")
	}
	b.PutID(StorePaymentPurposePremiumGiftCodesTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StorePaymentPurposePremiumGiftCodes) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposePremiumGiftCodes#1277b01d as nil")
	}
	b.PutInt53(s.BoostedChatID)
	b.PutString(s.Currency)
	b.PutInt53(s.Amount)
	b.PutInt(len(s.UserIDs))
	for _, v := range s.UserIDs {
		b.PutInt53(v)
	}
	if err := s.Text.Encode(b); err != nil {
		return fmt.Errorf("unable to encode storePaymentPurposePremiumGiftCodes#1277b01d: field text: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StorePaymentPurposePremiumGiftCodes) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode storePaymentPurposePremiumGiftCodes#1277b01d to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposePremiumGiftCodes#1277b01d: field boosted_chat_id: %w", err)
		}
		s.BoostedChatID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposePremiumGiftCodes#1277b01d: field currency: %w", err)
		}
		s.Currency = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposePremiumGiftCodes#1277b01d: field amount: %w", err)
		}
		s.Amount = value
	}
	{
		headerLen, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposePremiumGiftCodes#1277b01d: field user_ids: %w", err)
		}

		if headerLen > 0 {
			s.UserIDs = make([]int64, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumGiftCodes#1277b01d: field user_ids: %w", err)
			}
			s.UserIDs = append(s.UserIDs, value)
		}
	}
	{
		if err := s.Text.Decode(b); err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposePremiumGiftCodes#1277b01d: field text: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *StorePaymentPurposePremiumGiftCodes) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposePremiumGiftCodes#1277b01d as nil")
	}
	b.ObjStart()
	b.PutID("storePaymentPurposePremiumGiftCodes")
	b.Comma()
	b.FieldStart("boosted_chat_id")
	b.PutInt53(s.BoostedChatID)
	b.Comma()
	b.FieldStart("currency")
	b.PutString(s.Currency)
	b.Comma()
	b.FieldStart("amount")
	b.PutInt53(s.Amount)
	b.Comma()
	b.FieldStart("user_ids")
	b.ArrStart()
	for _, v := range s.UserIDs {
		b.PutInt53(v)
		b.Comma()
	}
	b.StripComma()
	b.ArrEnd()
	b.Comma()
	b.FieldStart("text")
	if err := s.Text.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode storePaymentPurposePremiumGiftCodes#1277b01d: field text: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *StorePaymentPurposePremiumGiftCodes) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode storePaymentPurposePremiumGiftCodes#1277b01d to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("storePaymentPurposePremiumGiftCodes"); err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumGiftCodes#1277b01d: %w", err)
			}
		case "boosted_chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumGiftCodes#1277b01d: field boosted_chat_id: %w", err)
			}
			s.BoostedChatID = value
		case "currency":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumGiftCodes#1277b01d: field currency: %w", err)
			}
			s.Currency = value
		case "amount":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumGiftCodes#1277b01d: field amount: %w", err)
			}
			s.Amount = value
		case "user_ids":
			if err := b.Arr(func(b tdjson.Decoder) error {
				value, err := b.Int53()
				if err != nil {
					return fmt.Errorf("unable to decode storePaymentPurposePremiumGiftCodes#1277b01d: field user_ids: %w", err)
				}
				s.UserIDs = append(s.UserIDs, value)
				return nil
			}); err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumGiftCodes#1277b01d: field user_ids: %w", err)
			}
		case "text":
			if err := s.Text.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumGiftCodes#1277b01d: field text: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetBoostedChatID returns value of BoostedChatID field.
func (s *StorePaymentPurposePremiumGiftCodes) GetBoostedChatID() (value int64) {
	if s == nil {
		return
	}
	return s.BoostedChatID
}

// GetCurrency returns value of Currency field.
func (s *StorePaymentPurposePremiumGiftCodes) GetCurrency() (value string) {
	if s == nil {
		return
	}
	return s.Currency
}

// GetAmount returns value of Amount field.
func (s *StorePaymentPurposePremiumGiftCodes) GetAmount() (value int64) {
	if s == nil {
		return
	}
	return s.Amount
}

// GetUserIDs returns value of UserIDs field.
func (s *StorePaymentPurposePremiumGiftCodes) GetUserIDs() (value []int64) {
	if s == nil {
		return
	}
	return s.UserIDs
}

// GetText returns value of Text field.
func (s *StorePaymentPurposePremiumGiftCodes) GetText() (value FormattedText) {
	if s == nil {
		return
	}
	return s.Text
}

// StorePaymentPurposePremiumGiveaway represents TL type `storePaymentPurposePremiumGiveaway#4da47aaa`.
type StorePaymentPurposePremiumGiveaway struct {
	// Giveaway parameters
	Parameters GiveawayParameters
	// ISO 4217 currency code of the payment currency
	Currency string
	// Paid amount, in the smallest units of the currency
	Amount int64
}

// StorePaymentPurposePremiumGiveawayTypeID is TL type id of StorePaymentPurposePremiumGiveaway.
const StorePaymentPurposePremiumGiveawayTypeID = 0x4da47aaa

// construct implements constructor of StorePaymentPurposeClass.
func (s StorePaymentPurposePremiumGiveaway) construct() StorePaymentPurposeClass { return &s }

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

	_ StorePaymentPurposeClass = &StorePaymentPurposePremiumGiveaway{}
)

func (s *StorePaymentPurposePremiumGiveaway) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Parameters.Zero()) {
		return false
	}
	if !(s.Currency == "") {
		return false
	}
	if !(s.Amount == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *StorePaymentPurposePremiumGiveaway) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "storePaymentPurposePremiumGiveaway",
		ID:   StorePaymentPurposePremiumGiveawayTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Parameters",
			SchemaName: "parameters",
		},
		{
			Name:       "Currency",
			SchemaName: "currency",
		},
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
	}
	return typ
}

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

// EncodeBare implements bin.BareEncoder.
func (s *StorePaymentPurposePremiumGiveaway) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposePremiumGiveaway#4da47aaa as nil")
	}
	if err := s.Parameters.Encode(b); err != nil {
		return fmt.Errorf("unable to encode storePaymentPurposePremiumGiveaway#4da47aaa: field parameters: %w", err)
	}
	b.PutString(s.Currency)
	b.PutInt53(s.Amount)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StorePaymentPurposePremiumGiveaway) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode storePaymentPurposePremiumGiveaway#4da47aaa to nil")
	}
	{
		if err := s.Parameters.Decode(b); err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposePremiumGiveaway#4da47aaa: field parameters: %w", err)
		}
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposePremiumGiveaway#4da47aaa: field currency: %w", err)
		}
		s.Currency = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposePremiumGiveaway#4da47aaa: field amount: %w", err)
		}
		s.Amount = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *StorePaymentPurposePremiumGiveaway) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposePremiumGiveaway#4da47aaa as nil")
	}
	b.ObjStart()
	b.PutID("storePaymentPurposePremiumGiveaway")
	b.Comma()
	b.FieldStart("parameters")
	if err := s.Parameters.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode storePaymentPurposePremiumGiveaway#4da47aaa: field parameters: %w", err)
	}
	b.Comma()
	b.FieldStart("currency")
	b.PutString(s.Currency)
	b.Comma()
	b.FieldStart("amount")
	b.PutInt53(s.Amount)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *StorePaymentPurposePremiumGiveaway) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode storePaymentPurposePremiumGiveaway#4da47aaa to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("storePaymentPurposePremiumGiveaway"); err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumGiveaway#4da47aaa: %w", err)
			}
		case "parameters":
			if err := s.Parameters.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumGiveaway#4da47aaa: field parameters: %w", err)
			}
		case "currency":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumGiveaway#4da47aaa: field currency: %w", err)
			}
			s.Currency = value
		case "amount":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposePremiumGiveaway#4da47aaa: field amount: %w", err)
			}
			s.Amount = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetParameters returns value of Parameters field.
func (s *StorePaymentPurposePremiumGiveaway) GetParameters() (value GiveawayParameters) {
	if s == nil {
		return
	}
	return s.Parameters
}

// GetCurrency returns value of Currency field.
func (s *StorePaymentPurposePremiumGiveaway) GetCurrency() (value string) {
	if s == nil {
		return
	}
	return s.Currency
}

// GetAmount returns value of Amount field.
func (s *StorePaymentPurposePremiumGiveaway) GetAmount() (value int64) {
	if s == nil {
		return
	}
	return s.Amount
}

// StorePaymentPurposeStarGiveaway represents TL type `storePaymentPurposeStarGiveaway#c96d899`.
type StorePaymentPurposeStarGiveaway struct {
	// Giveaway parameters
	Parameters GiveawayParameters
	// ISO 4217 currency code of the payment currency
	Currency string
	// Paid amount, in the smallest units of the currency
	Amount int64
	// The number of users to receive Telegram Stars
	WinnerCount int32
	// The number of Telegram Stars to be distributed through the giveaway
	StarCount int64
}

// StorePaymentPurposeStarGiveawayTypeID is TL type id of StorePaymentPurposeStarGiveaway.
const StorePaymentPurposeStarGiveawayTypeID = 0xc96d899

// construct implements constructor of StorePaymentPurposeClass.
func (s StorePaymentPurposeStarGiveaway) construct() StorePaymentPurposeClass { return &s }

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

	_ StorePaymentPurposeClass = &StorePaymentPurposeStarGiveaway{}
)

func (s *StorePaymentPurposeStarGiveaway) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Parameters.Zero()) {
		return false
	}
	if !(s.Currency == "") {
		return false
	}
	if !(s.Amount == 0) {
		return false
	}
	if !(s.WinnerCount == 0) {
		return false
	}
	if !(s.StarCount == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *StorePaymentPurposeStarGiveaway) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "storePaymentPurposeStarGiveaway",
		ID:   StorePaymentPurposeStarGiveawayTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Parameters",
			SchemaName: "parameters",
		},
		{
			Name:       "Currency",
			SchemaName: "currency",
		},
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
		{
			Name:       "WinnerCount",
			SchemaName: "winner_count",
		},
		{
			Name:       "StarCount",
			SchemaName: "star_count",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StorePaymentPurposeStarGiveaway) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposeStarGiveaway#c96d899 as nil")
	}
	b.PutID(StorePaymentPurposeStarGiveawayTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StorePaymentPurposeStarGiveaway) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposeStarGiveaway#c96d899 as nil")
	}
	if err := s.Parameters.Encode(b); err != nil {
		return fmt.Errorf("unable to encode storePaymentPurposeStarGiveaway#c96d899: field parameters: %w", err)
	}
	b.PutString(s.Currency)
	b.PutInt53(s.Amount)
	b.PutInt32(s.WinnerCount)
	b.PutInt53(s.StarCount)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StorePaymentPurposeStarGiveaway) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode storePaymentPurposeStarGiveaway#c96d899 to nil")
	}
	{
		if err := s.Parameters.Decode(b); err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposeStarGiveaway#c96d899: field parameters: %w", err)
		}
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposeStarGiveaway#c96d899: field currency: %w", err)
		}
		s.Currency = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposeStarGiveaway#c96d899: field amount: %w", err)
		}
		s.Amount = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposeStarGiveaway#c96d899: field winner_count: %w", err)
		}
		s.WinnerCount = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposeStarGiveaway#c96d899: field star_count: %w", err)
		}
		s.StarCount = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *StorePaymentPurposeStarGiveaway) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposeStarGiveaway#c96d899 as nil")
	}
	b.ObjStart()
	b.PutID("storePaymentPurposeStarGiveaway")
	b.Comma()
	b.FieldStart("parameters")
	if err := s.Parameters.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode storePaymentPurposeStarGiveaway#c96d899: field parameters: %w", err)
	}
	b.Comma()
	b.FieldStart("currency")
	b.PutString(s.Currency)
	b.Comma()
	b.FieldStart("amount")
	b.PutInt53(s.Amount)
	b.Comma()
	b.FieldStart("winner_count")
	b.PutInt32(s.WinnerCount)
	b.Comma()
	b.FieldStart("star_count")
	b.PutInt53(s.StarCount)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *StorePaymentPurposeStarGiveaway) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode storePaymentPurposeStarGiveaway#c96d899 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("storePaymentPurposeStarGiveaway"); err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposeStarGiveaway#c96d899: %w", err)
			}
		case "parameters":
			if err := s.Parameters.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposeStarGiveaway#c96d899: field parameters: %w", err)
			}
		case "currency":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposeStarGiveaway#c96d899: field currency: %w", err)
			}
			s.Currency = value
		case "amount":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposeStarGiveaway#c96d899: field amount: %w", err)
			}
			s.Amount = value
		case "winner_count":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposeStarGiveaway#c96d899: field winner_count: %w", err)
			}
			s.WinnerCount = value
		case "star_count":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposeStarGiveaway#c96d899: field star_count: %w", err)
			}
			s.StarCount = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetParameters returns value of Parameters field.
func (s *StorePaymentPurposeStarGiveaway) GetParameters() (value GiveawayParameters) {
	if s == nil {
		return
	}
	return s.Parameters
}

// GetCurrency returns value of Currency field.
func (s *StorePaymentPurposeStarGiveaway) GetCurrency() (value string) {
	if s == nil {
		return
	}
	return s.Currency
}

// GetAmount returns value of Amount field.
func (s *StorePaymentPurposeStarGiveaway) GetAmount() (value int64) {
	if s == nil {
		return
	}
	return s.Amount
}

// GetWinnerCount returns value of WinnerCount field.
func (s *StorePaymentPurposeStarGiveaway) GetWinnerCount() (value int32) {
	if s == nil {
		return
	}
	return s.WinnerCount
}

// GetStarCount returns value of StarCount field.
func (s *StorePaymentPurposeStarGiveaway) GetStarCount() (value int64) {
	if s == nil {
		return
	}
	return s.StarCount
}

// StorePaymentPurposeStars represents TL type `storePaymentPurposeStars#9480cf14`.
type StorePaymentPurposeStars struct {
	// ISO 4217 currency code of the payment currency
	Currency string
	// Paid amount, in the smallest units of the currency
	Amount int64
	// Number of bought Telegram Stars
	StarCount int64
}

// StorePaymentPurposeStarsTypeID is TL type id of StorePaymentPurposeStars.
const StorePaymentPurposeStarsTypeID = 0x9480cf14

// construct implements constructor of StorePaymentPurposeClass.
func (s StorePaymentPurposeStars) construct() StorePaymentPurposeClass { return &s }

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

	_ StorePaymentPurposeClass = &StorePaymentPurposeStars{}
)

func (s *StorePaymentPurposeStars) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Currency == "") {
		return false
	}
	if !(s.Amount == 0) {
		return false
	}
	if !(s.StarCount == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *StorePaymentPurposeStars) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "storePaymentPurposeStars",
		ID:   StorePaymentPurposeStarsTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Currency",
			SchemaName: "currency",
		},
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
		{
			Name:       "StarCount",
			SchemaName: "star_count",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StorePaymentPurposeStars) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposeStars#9480cf14 as nil")
	}
	b.PutID(StorePaymentPurposeStarsTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StorePaymentPurposeStars) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposeStars#9480cf14 as nil")
	}
	b.PutString(s.Currency)
	b.PutInt53(s.Amount)
	b.PutInt53(s.StarCount)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StorePaymentPurposeStars) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode storePaymentPurposeStars#9480cf14 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposeStars#9480cf14: field currency: %w", err)
		}
		s.Currency = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposeStars#9480cf14: field amount: %w", err)
		}
		s.Amount = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposeStars#9480cf14: field star_count: %w", err)
		}
		s.StarCount = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *StorePaymentPurposeStars) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposeStars#9480cf14 as nil")
	}
	b.ObjStart()
	b.PutID("storePaymentPurposeStars")
	b.Comma()
	b.FieldStart("currency")
	b.PutString(s.Currency)
	b.Comma()
	b.FieldStart("amount")
	b.PutInt53(s.Amount)
	b.Comma()
	b.FieldStart("star_count")
	b.PutInt53(s.StarCount)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *StorePaymentPurposeStars) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode storePaymentPurposeStars#9480cf14 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("storePaymentPurposeStars"); err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposeStars#9480cf14: %w", err)
			}
		case "currency":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposeStars#9480cf14: field currency: %w", err)
			}
			s.Currency = value
		case "amount":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposeStars#9480cf14: field amount: %w", err)
			}
			s.Amount = value
		case "star_count":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposeStars#9480cf14: field star_count: %w", err)
			}
			s.StarCount = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetCurrency returns value of Currency field.
func (s *StorePaymentPurposeStars) GetCurrency() (value string) {
	if s == nil {
		return
	}
	return s.Currency
}

// GetAmount returns value of Amount field.
func (s *StorePaymentPurposeStars) GetAmount() (value int64) {
	if s == nil {
		return
	}
	return s.Amount
}

// GetStarCount returns value of StarCount field.
func (s *StorePaymentPurposeStars) GetStarCount() (value int64) {
	if s == nil {
		return
	}
	return s.StarCount
}

// StorePaymentPurposeGiftedStars represents TL type `storePaymentPurposeGiftedStars#3544a624`.
type StorePaymentPurposeGiftedStars struct {
	// Identifier of the user to which Telegram Stars are gifted
	UserID int64
	// ISO 4217 currency code of the payment currency
	Currency string
	// Paid amount, in the smallest units of the currency
	Amount int64
	// Number of bought Telegram Stars
	StarCount int64
}

// StorePaymentPurposeGiftedStarsTypeID is TL type id of StorePaymentPurposeGiftedStars.
const StorePaymentPurposeGiftedStarsTypeID = 0x3544a624

// construct implements constructor of StorePaymentPurposeClass.
func (s StorePaymentPurposeGiftedStars) construct() StorePaymentPurposeClass { return &s }

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

	_ StorePaymentPurposeClass = &StorePaymentPurposeGiftedStars{}
)

func (s *StorePaymentPurposeGiftedStars) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.UserID == 0) {
		return false
	}
	if !(s.Currency == "") {
		return false
	}
	if !(s.Amount == 0) {
		return false
	}
	if !(s.StarCount == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *StorePaymentPurposeGiftedStars) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "storePaymentPurposeGiftedStars",
		ID:   StorePaymentPurposeGiftedStarsTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
		{
			Name:       "Currency",
			SchemaName: "currency",
		},
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
		{
			Name:       "StarCount",
			SchemaName: "star_count",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StorePaymentPurposeGiftedStars) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposeGiftedStars#3544a624 as nil")
	}
	b.PutID(StorePaymentPurposeGiftedStarsTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StorePaymentPurposeGiftedStars) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposeGiftedStars#3544a624 as nil")
	}
	b.PutInt53(s.UserID)
	b.PutString(s.Currency)
	b.PutInt53(s.Amount)
	b.PutInt53(s.StarCount)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StorePaymentPurposeGiftedStars) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode storePaymentPurposeGiftedStars#3544a624 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposeGiftedStars#3544a624: field user_id: %w", err)
		}
		s.UserID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposeGiftedStars#3544a624: field currency: %w", err)
		}
		s.Currency = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposeGiftedStars#3544a624: field amount: %w", err)
		}
		s.Amount = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode storePaymentPurposeGiftedStars#3544a624: field star_count: %w", err)
		}
		s.StarCount = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *StorePaymentPurposeGiftedStars) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode storePaymentPurposeGiftedStars#3544a624 as nil")
	}
	b.ObjStart()
	b.PutID("storePaymentPurposeGiftedStars")
	b.Comma()
	b.FieldStart("user_id")
	b.PutInt53(s.UserID)
	b.Comma()
	b.FieldStart("currency")
	b.PutString(s.Currency)
	b.Comma()
	b.FieldStart("amount")
	b.PutInt53(s.Amount)
	b.Comma()
	b.FieldStart("star_count")
	b.PutInt53(s.StarCount)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *StorePaymentPurposeGiftedStars) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode storePaymentPurposeGiftedStars#3544a624 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("storePaymentPurposeGiftedStars"); err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposeGiftedStars#3544a624: %w", err)
			}
		case "user_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposeGiftedStars#3544a624: field user_id: %w", err)
			}
			s.UserID = value
		case "currency":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposeGiftedStars#3544a624: field currency: %w", err)
			}
			s.Currency = value
		case "amount":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposeGiftedStars#3544a624: field amount: %w", err)
			}
			s.Amount = value
		case "star_count":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode storePaymentPurposeGiftedStars#3544a624: field star_count: %w", err)
			}
			s.StarCount = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetUserID returns value of UserID field.
func (s *StorePaymentPurposeGiftedStars) GetUserID() (value int64) {
	if s == nil {
		return
	}
	return s.UserID
}

// GetCurrency returns value of Currency field.
func (s *StorePaymentPurposeGiftedStars) GetCurrency() (value string) {
	if s == nil {
		return
	}
	return s.Currency
}

// GetAmount returns value of Amount field.
func (s *StorePaymentPurposeGiftedStars) GetAmount() (value int64) {
	if s == nil {
		return
	}
	return s.Amount
}

// GetStarCount returns value of StarCount field.
func (s *StorePaymentPurposeGiftedStars) GetStarCount() (value int64) {
	if s == nil {
		return
	}
	return s.StarCount
}

// StorePaymentPurposeClassName is schema name of StorePaymentPurposeClass.
const StorePaymentPurposeClassName = "StorePaymentPurpose"

// StorePaymentPurposeClass represents StorePaymentPurpose generic type.
//
// Example:
//
//	g, err := tdapi.DecodeStorePaymentPurpose(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.StorePaymentPurposePremiumSubscription: // storePaymentPurposePremiumSubscription#4b558114
//	case *tdapi.StorePaymentPurposePremiumGift: // storePaymentPurposePremiumGift#fda53d95
//	case *tdapi.StorePaymentPurposePremiumGiftCodes: // storePaymentPurposePremiumGiftCodes#1277b01d
//	case *tdapi.StorePaymentPurposePremiumGiveaway: // storePaymentPurposePremiumGiveaway#4da47aaa
//	case *tdapi.StorePaymentPurposeStarGiveaway: // storePaymentPurposeStarGiveaway#c96d899
//	case *tdapi.StorePaymentPurposeStars: // storePaymentPurposeStars#9480cf14
//	case *tdapi.StorePaymentPurposeGiftedStars: // storePaymentPurposeGiftedStars#3544a624
//	default: panic(v)
//	}
type StorePaymentPurposeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() StorePaymentPurposeClass

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

// DecodeStorePaymentPurpose implements binary de-serialization for StorePaymentPurposeClass.
func DecodeStorePaymentPurpose(buf *bin.Buffer) (StorePaymentPurposeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case StorePaymentPurposePremiumSubscriptionTypeID:
		// Decoding storePaymentPurposePremiumSubscription#4b558114.
		v := StorePaymentPurposePremiumSubscription{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StorePaymentPurposeClass: %w", err)
		}
		return &v, nil
	case StorePaymentPurposePremiumGiftTypeID:
		// Decoding storePaymentPurposePremiumGift#fda53d95.
		v := StorePaymentPurposePremiumGift{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StorePaymentPurposeClass: %w", err)
		}
		return &v, nil
	case StorePaymentPurposePremiumGiftCodesTypeID:
		// Decoding storePaymentPurposePremiumGiftCodes#1277b01d.
		v := StorePaymentPurposePremiumGiftCodes{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StorePaymentPurposeClass: %w", err)
		}
		return &v, nil
	case StorePaymentPurposePremiumGiveawayTypeID:
		// Decoding storePaymentPurposePremiumGiveaway#4da47aaa.
		v := StorePaymentPurposePremiumGiveaway{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StorePaymentPurposeClass: %w", err)
		}
		return &v, nil
	case StorePaymentPurposeStarGiveawayTypeID:
		// Decoding storePaymentPurposeStarGiveaway#c96d899.
		v := StorePaymentPurposeStarGiveaway{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StorePaymentPurposeClass: %w", err)
		}
		return &v, nil
	case StorePaymentPurposeStarsTypeID:
		// Decoding storePaymentPurposeStars#9480cf14.
		v := StorePaymentPurposeStars{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StorePaymentPurposeClass: %w", err)
		}
		return &v, nil
	case StorePaymentPurposeGiftedStarsTypeID:
		// Decoding storePaymentPurposeGiftedStars#3544a624.
		v := StorePaymentPurposeGiftedStars{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StorePaymentPurposeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode StorePaymentPurposeClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONStorePaymentPurpose implements binary de-serialization for StorePaymentPurposeClass.
func DecodeTDLibJSONStorePaymentPurpose(buf tdjson.Decoder) (StorePaymentPurposeClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "storePaymentPurposePremiumSubscription":
		// Decoding storePaymentPurposePremiumSubscription#4b558114.
		v := StorePaymentPurposePremiumSubscription{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StorePaymentPurposeClass: %w", err)
		}
		return &v, nil
	case "storePaymentPurposePremiumGift":
		// Decoding storePaymentPurposePremiumGift#fda53d95.
		v := StorePaymentPurposePremiumGift{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StorePaymentPurposeClass: %w", err)
		}
		return &v, nil
	case "storePaymentPurposePremiumGiftCodes":
		// Decoding storePaymentPurposePremiumGiftCodes#1277b01d.
		v := StorePaymentPurposePremiumGiftCodes{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StorePaymentPurposeClass: %w", err)
		}
		return &v, nil
	case "storePaymentPurposePremiumGiveaway":
		// Decoding storePaymentPurposePremiumGiveaway#4da47aaa.
		v := StorePaymentPurposePremiumGiveaway{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StorePaymentPurposeClass: %w", err)
		}
		return &v, nil
	case "storePaymentPurposeStarGiveaway":
		// Decoding storePaymentPurposeStarGiveaway#c96d899.
		v := StorePaymentPurposeStarGiveaway{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StorePaymentPurposeClass: %w", err)
		}
		return &v, nil
	case "storePaymentPurposeStars":
		// Decoding storePaymentPurposeStars#9480cf14.
		v := StorePaymentPurposeStars{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StorePaymentPurposeClass: %w", err)
		}
		return &v, nil
	case "storePaymentPurposeGiftedStars":
		// Decoding storePaymentPurposeGiftedStars#3544a624.
		v := StorePaymentPurposeGiftedStars{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StorePaymentPurposeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode StorePaymentPurposeClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// StorePaymentPurpose boxes the StorePaymentPurposeClass providing a helper.
type StorePaymentPurposeBox struct {
	StorePaymentPurpose StorePaymentPurposeClass
}

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

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

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

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