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

// TelegramPaymentPurposePremiumGift represents TL type `telegramPaymentPurposePremiumGift#a09d923a`.
type TelegramPaymentPurposePremiumGift struct {
	// ISO 4217 currency code of the payment currency, or "XTR" for payments in Telegram
	// Stars
	Currency string
	// Paid amount, in the smallest units of the currency
	Amount int64
	// Identifier of the user which will receive Telegram Premium
	UserID int64
	// Number of months the Telegram Premium subscription will be active for the user
	MonthCount int32
	// Text to show to the user receiving Telegram Premium;
	// 0-getOption("gift_text_length_max") characters. Only Bold, Italic, Underline,
	// Strikethrough, Spoiler, and CustomEmoji entities are allowed
	Text FormattedText
}

// TelegramPaymentPurposePremiumGiftTypeID is TL type id of TelegramPaymentPurposePremiumGift.
const TelegramPaymentPurposePremiumGiftTypeID = 0xa09d923a

// construct implements constructor of TelegramPaymentPurposeClass.
func (t TelegramPaymentPurposePremiumGift) construct() TelegramPaymentPurposeClass { return &t }

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

	_ TelegramPaymentPurposeClass = &TelegramPaymentPurposePremiumGift{}
)

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (t *TelegramPaymentPurposePremiumGift) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode telegramPaymentPurposePremiumGift#a09d923a as nil")
	}
	b.PutID(TelegramPaymentPurposePremiumGiftTypeID)
	return t.EncodeBare(b)
}

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

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

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

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

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

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

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

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

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

// GetMonthCount returns value of MonthCount field.
func (t *TelegramPaymentPurposePremiumGift) GetMonthCount() (value int32) {
	if t == nil {
		return
	}
	return t.MonthCount
}

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

// TelegramPaymentPurposePremiumGiftCodes represents TL type `telegramPaymentPurposePremiumGiftCodes#b13f14a9`.
type TelegramPaymentPurposePremiumGiftCodes 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
	// Number of months the Telegram Premium subscription will be active for the users
	MonthCount int32
	// 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
}

// TelegramPaymentPurposePremiumGiftCodesTypeID is TL type id of TelegramPaymentPurposePremiumGiftCodes.
const TelegramPaymentPurposePremiumGiftCodesTypeID = 0xb13f14a9

// construct implements constructor of TelegramPaymentPurposeClass.
func (t TelegramPaymentPurposePremiumGiftCodes) construct() TelegramPaymentPurposeClass { return &t }

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

	_ TelegramPaymentPurposeClass = &TelegramPaymentPurposePremiumGiftCodes{}
)

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *TelegramPaymentPurposePremiumGiftCodes) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "telegramPaymentPurposePremiumGiftCodes",
		ID:   TelegramPaymentPurposePremiumGiftCodesTypeID,
	}
	if t == 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:       "MonthCount",
			SchemaName: "month_count",
		},
		{
			Name:       "Text",
			SchemaName: "text",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *TelegramPaymentPurposePremiumGiftCodes) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode telegramPaymentPurposePremiumGiftCodes#b13f14a9 as nil")
	}
	b.PutID(TelegramPaymentPurposePremiumGiftCodesTypeID)
	return t.EncodeBare(b)
}

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

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

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

		if headerLen > 0 {
			t.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 telegramPaymentPurposePremiumGiftCodes#b13f14a9: field user_ids: %w", err)
			}
			t.UserIDs = append(t.UserIDs, value)
		}
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode telegramPaymentPurposePremiumGiftCodes#b13f14a9: field month_count: %w", err)
		}
		t.MonthCount = value
	}
	{
		if err := t.Text.Decode(b); err != nil {
			return fmt.Errorf("unable to decode telegramPaymentPurposePremiumGiftCodes#b13f14a9: field text: %w", err)
		}
	}
	return nil
}

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

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("telegramPaymentPurposePremiumGiftCodes"); err != nil {
				return fmt.Errorf("unable to decode telegramPaymentPurposePremiumGiftCodes#b13f14a9: %w", err)
			}
		case "boosted_chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode telegramPaymentPurposePremiumGiftCodes#b13f14a9: field boosted_chat_id: %w", err)
			}
			t.BoostedChatID = value
		case "currency":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode telegramPaymentPurposePremiumGiftCodes#b13f14a9: field currency: %w", err)
			}
			t.Currency = value
		case "amount":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode telegramPaymentPurposePremiumGiftCodes#b13f14a9: field amount: %w", err)
			}
			t.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 telegramPaymentPurposePremiumGiftCodes#b13f14a9: field user_ids: %w", err)
				}
				t.UserIDs = append(t.UserIDs, value)
				return nil
			}); err != nil {
				return fmt.Errorf("unable to decode telegramPaymentPurposePremiumGiftCodes#b13f14a9: field user_ids: %w", err)
			}
		case "month_count":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode telegramPaymentPurposePremiumGiftCodes#b13f14a9: field month_count: %w", err)
			}
			t.MonthCount = value
		case "text":
			if err := t.Text.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode telegramPaymentPurposePremiumGiftCodes#b13f14a9: field text: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

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

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

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

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

// GetMonthCount returns value of MonthCount field.
func (t *TelegramPaymentPurposePremiumGiftCodes) GetMonthCount() (value int32) {
	if t == nil {
		return
	}
	return t.MonthCount
}

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

// TelegramPaymentPurposePremiumGiveaway represents TL type `telegramPaymentPurposePremiumGiveaway#d2a7c33f`.
type TelegramPaymentPurposePremiumGiveaway 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
	// Number of users which will be able to activate the gift codes
	WinnerCount int32
	// Number of months the Telegram Premium subscription will be active for the users
	MonthCount int32
}

// TelegramPaymentPurposePremiumGiveawayTypeID is TL type id of TelegramPaymentPurposePremiumGiveaway.
const TelegramPaymentPurposePremiumGiveawayTypeID = 0xd2a7c33f

// construct implements constructor of TelegramPaymentPurposeClass.
func (t TelegramPaymentPurposePremiumGiveaway) construct() TelegramPaymentPurposeClass { return &t }

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

	_ TelegramPaymentPurposeClass = &TelegramPaymentPurposePremiumGiveaway{}
)

func (t *TelegramPaymentPurposePremiumGiveaway) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.Parameters.Zero()) {
		return false
	}
	if !(t.Currency == "") {
		return false
	}
	if !(t.Amount == 0) {
		return false
	}
	if !(t.WinnerCount == 0) {
		return false
	}
	if !(t.MonthCount == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *TelegramPaymentPurposePremiumGiveaway) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "telegramPaymentPurposePremiumGiveaway",
		ID:   TelegramPaymentPurposePremiumGiveawayTypeID,
	}
	if t == 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:       "MonthCount",
			SchemaName: "month_count",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *TelegramPaymentPurposePremiumGiveaway) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode telegramPaymentPurposePremiumGiveaway#d2a7c33f as nil")
	}
	b.PutID(TelegramPaymentPurposePremiumGiveawayTypeID)
	return t.EncodeBare(b)
}

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

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

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

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

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

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

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

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

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

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

// GetMonthCount returns value of MonthCount field.
func (t *TelegramPaymentPurposePremiumGiveaway) GetMonthCount() (value int32) {
	if t == nil {
		return
	}
	return t.MonthCount
}

// TelegramPaymentPurposeStars represents TL type `telegramPaymentPurposeStars#e273ee52`.
type TelegramPaymentPurposeStars 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
}

// TelegramPaymentPurposeStarsTypeID is TL type id of TelegramPaymentPurposeStars.
const TelegramPaymentPurposeStarsTypeID = 0xe273ee52

// construct implements constructor of TelegramPaymentPurposeClass.
func (t TelegramPaymentPurposeStars) construct() TelegramPaymentPurposeClass { return &t }

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

	_ TelegramPaymentPurposeClass = &TelegramPaymentPurposeStars{}
)

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *TelegramPaymentPurposeStars) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "telegramPaymentPurposeStars",
		ID:   TelegramPaymentPurposeStarsTypeID,
	}
	if t == 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 (t *TelegramPaymentPurposeStars) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode telegramPaymentPurposeStars#e273ee52 as nil")
	}
	b.PutID(TelegramPaymentPurposeStarsTypeID)
	return t.EncodeBare(b)
}

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

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

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

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

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

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

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

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

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

// TelegramPaymentPurposeGiftedStars represents TL type `telegramPaymentPurposeGiftedStars#91b68a36`.
type TelegramPaymentPurposeGiftedStars 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
}

// TelegramPaymentPurposeGiftedStarsTypeID is TL type id of TelegramPaymentPurposeGiftedStars.
const TelegramPaymentPurposeGiftedStarsTypeID = 0x91b68a36

// construct implements constructor of TelegramPaymentPurposeClass.
func (t TelegramPaymentPurposeGiftedStars) construct() TelegramPaymentPurposeClass { return &t }

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

	_ TelegramPaymentPurposeClass = &TelegramPaymentPurposeGiftedStars{}
)

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *TelegramPaymentPurposeGiftedStars) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "telegramPaymentPurposeGiftedStars",
		ID:   TelegramPaymentPurposeGiftedStarsTypeID,
	}
	if t == 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 (t *TelegramPaymentPurposeGiftedStars) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode telegramPaymentPurposeGiftedStars#91b68a36 as nil")
	}
	b.PutID(TelegramPaymentPurposeGiftedStarsTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *TelegramPaymentPurposeGiftedStars) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode telegramPaymentPurposeGiftedStars#91b68a36 as nil")
	}
	b.PutInt53(t.UserID)
	b.PutString(t.Currency)
	b.PutInt53(t.Amount)
	b.PutInt53(t.StarCount)
	return nil
}

// Decode implements bin.Decoder.
func (t *TelegramPaymentPurposeGiftedStars) Decode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode telegramPaymentPurposeGiftedStars#91b68a36 to nil")
	}
	if err := b.ConsumeID(TelegramPaymentPurposeGiftedStarsTypeID); err != nil {
		return fmt.Errorf("unable to decode telegramPaymentPurposeGiftedStars#91b68a36: %w", err)
	}
	return t.DecodeBare(b)
}

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

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

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (t *TelegramPaymentPurposeGiftedStars) DecodeTDLibJSON(b tdjson.Decoder) error {
	if t == nil {
		return fmt.Errorf("can't decode telegramPaymentPurposeGiftedStars#91b68a36 to nil")
	}

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

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

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

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

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

// TelegramPaymentPurposeStarGiveaway represents TL type `telegramPaymentPurposeStarGiveaway#3c79a391`.
type TelegramPaymentPurposeStarGiveaway 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
}

// TelegramPaymentPurposeStarGiveawayTypeID is TL type id of TelegramPaymentPurposeStarGiveaway.
const TelegramPaymentPurposeStarGiveawayTypeID = 0x3c79a391

// construct implements constructor of TelegramPaymentPurposeClass.
func (t TelegramPaymentPurposeStarGiveaway) construct() TelegramPaymentPurposeClass { return &t }

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

	_ TelegramPaymentPurposeClass = &TelegramPaymentPurposeStarGiveaway{}
)

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *TelegramPaymentPurposeStarGiveaway) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "telegramPaymentPurposeStarGiveaway",
		ID:   TelegramPaymentPurposeStarGiveawayTypeID,
	}
	if t == 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 (t *TelegramPaymentPurposeStarGiveaway) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode telegramPaymentPurposeStarGiveaway#3c79a391 as nil")
	}
	b.PutID(TelegramPaymentPurposeStarGiveawayTypeID)
	return t.EncodeBare(b)
}

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

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

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

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

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (t *TelegramPaymentPurposeStarGiveaway) DecodeTDLibJSON(b tdjson.Decoder) error {
	if t == nil {
		return fmt.Errorf("can't decode telegramPaymentPurposeStarGiveaway#3c79a391 to nil")
	}

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

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

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

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

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

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

// TelegramPaymentPurposeJoinChat represents TL type `telegramPaymentPurposeJoinChat#8ddd6788`.
type TelegramPaymentPurposeJoinChat struct {
	// Invite link to use
	InviteLink string
}

// TelegramPaymentPurposeJoinChatTypeID is TL type id of TelegramPaymentPurposeJoinChat.
const TelegramPaymentPurposeJoinChatTypeID = 0x8ddd6788

// construct implements constructor of TelegramPaymentPurposeClass.
func (t TelegramPaymentPurposeJoinChat) construct() TelegramPaymentPurposeClass { return &t }

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

	_ TelegramPaymentPurposeClass = &TelegramPaymentPurposeJoinChat{}
)

func (t *TelegramPaymentPurposeJoinChat) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.InviteLink == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *TelegramPaymentPurposeJoinChat) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "telegramPaymentPurposeJoinChat",
		ID:   TelegramPaymentPurposeJoinChatTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "InviteLink",
			SchemaName: "invite_link",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *TelegramPaymentPurposeJoinChat) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode telegramPaymentPurposeJoinChat#8ddd6788 as nil")
	}
	b.PutID(TelegramPaymentPurposeJoinChatTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *TelegramPaymentPurposeJoinChat) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode telegramPaymentPurposeJoinChat#8ddd6788 as nil")
	}
	b.PutString(t.InviteLink)
	return nil
}

// Decode implements bin.Decoder.
func (t *TelegramPaymentPurposeJoinChat) Decode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode telegramPaymentPurposeJoinChat#8ddd6788 to nil")
	}
	if err := b.ConsumeID(TelegramPaymentPurposeJoinChatTypeID); err != nil {
		return fmt.Errorf("unable to decode telegramPaymentPurposeJoinChat#8ddd6788: %w", err)
	}
	return t.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (t *TelegramPaymentPurposeJoinChat) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode telegramPaymentPurposeJoinChat#8ddd6788 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode telegramPaymentPurposeJoinChat#8ddd6788: field invite_link: %w", err)
		}
		t.InviteLink = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *TelegramPaymentPurposeJoinChat) EncodeTDLibJSON(b tdjson.Encoder) error {
	if t == nil {
		return fmt.Errorf("can't encode telegramPaymentPurposeJoinChat#8ddd6788 as nil")
	}
	b.ObjStart()
	b.PutID("telegramPaymentPurposeJoinChat")
	b.Comma()
	b.FieldStart("invite_link")
	b.PutString(t.InviteLink)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (t *TelegramPaymentPurposeJoinChat) DecodeTDLibJSON(b tdjson.Decoder) error {
	if t == nil {
		return fmt.Errorf("can't decode telegramPaymentPurposeJoinChat#8ddd6788 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("telegramPaymentPurposeJoinChat"); err != nil {
				return fmt.Errorf("unable to decode telegramPaymentPurposeJoinChat#8ddd6788: %w", err)
			}
		case "invite_link":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode telegramPaymentPurposeJoinChat#8ddd6788: field invite_link: %w", err)
			}
			t.InviteLink = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetInviteLink returns value of InviteLink field.
func (t *TelegramPaymentPurposeJoinChat) GetInviteLink() (value string) {
	if t == nil {
		return
	}
	return t.InviteLink
}

// TelegramPaymentPurposeClassName is schema name of TelegramPaymentPurposeClass.
const TelegramPaymentPurposeClassName = "TelegramPaymentPurpose"

// TelegramPaymentPurposeClass represents TelegramPaymentPurpose generic type.
//
// Example:
//
//	g, err := tdapi.DecodeTelegramPaymentPurpose(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.TelegramPaymentPurposePremiumGift: // telegramPaymentPurposePremiumGift#a09d923a
//	case *tdapi.TelegramPaymentPurposePremiumGiftCodes: // telegramPaymentPurposePremiumGiftCodes#b13f14a9
//	case *tdapi.TelegramPaymentPurposePremiumGiveaway: // telegramPaymentPurposePremiumGiveaway#d2a7c33f
//	case *tdapi.TelegramPaymentPurposeStars: // telegramPaymentPurposeStars#e273ee52
//	case *tdapi.TelegramPaymentPurposeGiftedStars: // telegramPaymentPurposeGiftedStars#91b68a36
//	case *tdapi.TelegramPaymentPurposeStarGiveaway: // telegramPaymentPurposeStarGiveaway#3c79a391
//	case *tdapi.TelegramPaymentPurposeJoinChat: // telegramPaymentPurposeJoinChat#8ddd6788
//	default: panic(v)
//	}
type TelegramPaymentPurposeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() TelegramPaymentPurposeClass

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

// DecodeTelegramPaymentPurpose implements binary de-serialization for TelegramPaymentPurposeClass.
func DecodeTelegramPaymentPurpose(buf *bin.Buffer) (TelegramPaymentPurposeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case TelegramPaymentPurposePremiumGiftTypeID:
		// Decoding telegramPaymentPurposePremiumGift#a09d923a.
		v := TelegramPaymentPurposePremiumGift{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TelegramPaymentPurposeClass: %w", err)
		}
		return &v, nil
	case TelegramPaymentPurposePremiumGiftCodesTypeID:
		// Decoding telegramPaymentPurposePremiumGiftCodes#b13f14a9.
		v := TelegramPaymentPurposePremiumGiftCodes{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TelegramPaymentPurposeClass: %w", err)
		}
		return &v, nil
	case TelegramPaymentPurposePremiumGiveawayTypeID:
		// Decoding telegramPaymentPurposePremiumGiveaway#d2a7c33f.
		v := TelegramPaymentPurposePremiumGiveaway{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TelegramPaymentPurposeClass: %w", err)
		}
		return &v, nil
	case TelegramPaymentPurposeStarsTypeID:
		// Decoding telegramPaymentPurposeStars#e273ee52.
		v := TelegramPaymentPurposeStars{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TelegramPaymentPurposeClass: %w", err)
		}
		return &v, nil
	case TelegramPaymentPurposeGiftedStarsTypeID:
		// Decoding telegramPaymentPurposeGiftedStars#91b68a36.
		v := TelegramPaymentPurposeGiftedStars{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TelegramPaymentPurposeClass: %w", err)
		}
		return &v, nil
	case TelegramPaymentPurposeStarGiveawayTypeID:
		// Decoding telegramPaymentPurposeStarGiveaway#3c79a391.
		v := TelegramPaymentPurposeStarGiveaway{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TelegramPaymentPurposeClass: %w", err)
		}
		return &v, nil
	case TelegramPaymentPurposeJoinChatTypeID:
		// Decoding telegramPaymentPurposeJoinChat#8ddd6788.
		v := TelegramPaymentPurposeJoinChat{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TelegramPaymentPurposeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode TelegramPaymentPurposeClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONTelegramPaymentPurpose implements binary de-serialization for TelegramPaymentPurposeClass.
func DecodeTDLibJSONTelegramPaymentPurpose(buf tdjson.Decoder) (TelegramPaymentPurposeClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "telegramPaymentPurposePremiumGift":
		// Decoding telegramPaymentPurposePremiumGift#a09d923a.
		v := TelegramPaymentPurposePremiumGift{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TelegramPaymentPurposeClass: %w", err)
		}
		return &v, nil
	case "telegramPaymentPurposePremiumGiftCodes":
		// Decoding telegramPaymentPurposePremiumGiftCodes#b13f14a9.
		v := TelegramPaymentPurposePremiumGiftCodes{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TelegramPaymentPurposeClass: %w", err)
		}
		return &v, nil
	case "telegramPaymentPurposePremiumGiveaway":
		// Decoding telegramPaymentPurposePremiumGiveaway#d2a7c33f.
		v := TelegramPaymentPurposePremiumGiveaway{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TelegramPaymentPurposeClass: %w", err)
		}
		return &v, nil
	case "telegramPaymentPurposeStars":
		// Decoding telegramPaymentPurposeStars#e273ee52.
		v := TelegramPaymentPurposeStars{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TelegramPaymentPurposeClass: %w", err)
		}
		return &v, nil
	case "telegramPaymentPurposeGiftedStars":
		// Decoding telegramPaymentPurposeGiftedStars#91b68a36.
		v := TelegramPaymentPurposeGiftedStars{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TelegramPaymentPurposeClass: %w", err)
		}
		return &v, nil
	case "telegramPaymentPurposeStarGiveaway":
		// Decoding telegramPaymentPurposeStarGiveaway#3c79a391.
		v := TelegramPaymentPurposeStarGiveaway{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TelegramPaymentPurposeClass: %w", err)
		}
		return &v, nil
	case "telegramPaymentPurposeJoinChat":
		// Decoding telegramPaymentPurposeJoinChat#8ddd6788.
		v := TelegramPaymentPurposeJoinChat{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TelegramPaymentPurposeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode TelegramPaymentPurposeClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// TelegramPaymentPurpose boxes the TelegramPaymentPurposeClass providing a helper.
type TelegramPaymentPurposeBox struct {
	TelegramPaymentPurpose TelegramPaymentPurposeClass
}

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

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

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

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