// 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{} ) // PremiumGiveawayPaymentOption represents TL type `premiumGiveawayPaymentOption#4184cb88`. type PremiumGiveawayPaymentOption struct { // ISO 4217 currency code for Telegram Premium gift code payment Currency string // The amount to pay, 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 MonthCount int32 // Identifier of the store product associated with the option; may be empty if none StoreProductID string // Number of times the store product must be paid StoreProductQuantity int32 } // PremiumGiveawayPaymentOptionTypeID is TL type id of PremiumGiveawayPaymentOption. const PremiumGiveawayPaymentOptionTypeID = 0x4184cb88 // Ensuring interfaces in compile-time for PremiumGiveawayPaymentOption. var ( _ bin.Encoder = &PremiumGiveawayPaymentOption{} _ bin.Decoder = &PremiumGiveawayPaymentOption{} _ bin.BareEncoder = &PremiumGiveawayPaymentOption{} _ bin.BareDecoder = &PremiumGiveawayPaymentOption{} ) func (p *PremiumGiveawayPaymentOption) Zero() bool { if p == nil { return true } if !(p.Currency == "") { return false } if !(p.Amount == 0) { return false } if !(p.WinnerCount == 0) { return false } if !(p.MonthCount == 0) { return false } if !(p.StoreProductID == "") { return false } if !(p.StoreProductQuantity == 0) { return false } return true } // String implements fmt.Stringer. func (p *PremiumGiveawayPaymentOption) String() string { if p == nil { return "PremiumGiveawayPaymentOption(nil)" } type Alias PremiumGiveawayPaymentOption return fmt.Sprintf("PremiumGiveawayPaymentOption%+v", Alias(*p)) } // TypeID returns type id in TL schema. // // See https://core.telegram.org/mtproto/TL-tl#remarks. func (*PremiumGiveawayPaymentOption) TypeID() uint32 { return PremiumGiveawayPaymentOptionTypeID } // TypeName returns name of type in TL schema. func (*PremiumGiveawayPaymentOption) TypeName() string { return "premiumGiveawayPaymentOption" } // TypeInfo returns info about TL type. func (p *PremiumGiveawayPaymentOption) TypeInfo() tdp.Type { typ := tdp.Type{ Name: "premiumGiveawayPaymentOption", ID: PremiumGiveawayPaymentOptionTypeID, } if p == nil { typ.Null = true return typ } typ.Fields = []tdp.Field{ { Name: "Currency", SchemaName: "currency", }, { Name: "Amount", SchemaName: "amount", }, { Name: "WinnerCount", SchemaName: "winner_count", }, { Name: "MonthCount", SchemaName: "month_count", }, { Name: "StoreProductID", SchemaName: "store_product_id", }, { Name: "StoreProductQuantity", SchemaName: "store_product_quantity", }, } return typ } // Encode implements bin.Encoder. func (p *PremiumGiveawayPaymentOption) Encode(b *bin.Buffer) error { if p == nil { return fmt.Errorf("can't encode premiumGiveawayPaymentOption#4184cb88 as nil") } b.PutID(PremiumGiveawayPaymentOptionTypeID) return p.EncodeBare(b) } // EncodeBare implements bin.BareEncoder. func (p *PremiumGiveawayPaymentOption) EncodeBare(b *bin.Buffer) error { if p == nil { return fmt.Errorf("can't encode premiumGiveawayPaymentOption#4184cb88 as nil") } b.PutString(p.Currency) b.PutInt53(p.Amount) b.PutInt32(p.WinnerCount) b.PutInt32(p.MonthCount) b.PutString(p.StoreProductID) b.PutInt32(p.StoreProductQuantity) return nil } // Decode implements bin.Decoder. func (p *PremiumGiveawayPaymentOption) Decode(b *bin.Buffer) error { if p == nil { return fmt.Errorf("can't decode premiumGiveawayPaymentOption#4184cb88 to nil") } if err := b.ConsumeID(PremiumGiveawayPaymentOptionTypeID); err != nil { return fmt.Errorf("unable to decode premiumGiveawayPaymentOption#4184cb88: %w", err) } return p.DecodeBare(b) } // DecodeBare implements bin.BareDecoder. func (p *PremiumGiveawayPaymentOption) DecodeBare(b *bin.Buffer) error { if p == nil { return fmt.Errorf("can't decode premiumGiveawayPaymentOption#4184cb88 to nil") } { value, err := b.String() if err != nil { return fmt.Errorf("unable to decode premiumGiveawayPaymentOption#4184cb88: field currency: %w", err) } p.Currency = value } { value, err := b.Int53() if err != nil { return fmt.Errorf("unable to decode premiumGiveawayPaymentOption#4184cb88: field amount: %w", err) } p.Amount = value } { value, err := b.Int32() if err != nil { return fmt.Errorf("unable to decode premiumGiveawayPaymentOption#4184cb88: field winner_count: %w", err) } p.WinnerCount = value } { value, err := b.Int32() if err != nil { return fmt.Errorf("unable to decode premiumGiveawayPaymentOption#4184cb88: field month_count: %w", err) } p.MonthCount = value } { value, err := b.String() if err != nil { return fmt.Errorf("unable to decode premiumGiveawayPaymentOption#4184cb88: field store_product_id: %w", err) } p.StoreProductID = value } { value, err := b.Int32() if err != nil { return fmt.Errorf("unable to decode premiumGiveawayPaymentOption#4184cb88: field store_product_quantity: %w", err) } p.StoreProductQuantity = value } return nil } // EncodeTDLibJSON implements tdjson.TDLibEncoder. func (p *PremiumGiveawayPaymentOption) EncodeTDLibJSON(b tdjson.Encoder) error { if p == nil { return fmt.Errorf("can't encode premiumGiveawayPaymentOption#4184cb88 as nil") } b.ObjStart() b.PutID("premiumGiveawayPaymentOption") b.Comma() b.FieldStart("currency") b.PutString(p.Currency) b.Comma() b.FieldStart("amount") b.PutInt53(p.Amount) b.Comma() b.FieldStart("winner_count") b.PutInt32(p.WinnerCount) b.Comma() b.FieldStart("month_count") b.PutInt32(p.MonthCount) b.Comma() b.FieldStart("store_product_id") b.PutString(p.StoreProductID) b.Comma() b.FieldStart("store_product_quantity") b.PutInt32(p.StoreProductQuantity) b.Comma() b.StripComma() b.ObjEnd() return nil } // DecodeTDLibJSON implements tdjson.TDLibDecoder. func (p *PremiumGiveawayPaymentOption) DecodeTDLibJSON(b tdjson.Decoder) error { if p == nil { return fmt.Errorf("can't decode premiumGiveawayPaymentOption#4184cb88 to nil") } return b.Obj(func(b tdjson.Decoder, key []byte) error { switch string(key) { case tdjson.TypeField: if err := b.ConsumeID("premiumGiveawayPaymentOption"); err != nil { return fmt.Errorf("unable to decode premiumGiveawayPaymentOption#4184cb88: %w", err) } case "currency": value, err := b.String() if err != nil { return fmt.Errorf("unable to decode premiumGiveawayPaymentOption#4184cb88: field currency: %w", err) } p.Currency = value case "amount": value, err := b.Int53() if err != nil { return fmt.Errorf("unable to decode premiumGiveawayPaymentOption#4184cb88: field amount: %w", err) } p.Amount = value case "winner_count": value, err := b.Int32() if err != nil { return fmt.Errorf("unable to decode premiumGiveawayPaymentOption#4184cb88: field winner_count: %w", err) } p.WinnerCount = value case "month_count": value, err := b.Int32() if err != nil { return fmt.Errorf("unable to decode premiumGiveawayPaymentOption#4184cb88: field month_count: %w", err) } p.MonthCount = value case "store_product_id": value, err := b.String() if err != nil { return fmt.Errorf("unable to decode premiumGiveawayPaymentOption#4184cb88: field store_product_id: %w", err) } p.StoreProductID = value case "store_product_quantity": value, err := b.Int32() if err != nil { return fmt.Errorf("unable to decode premiumGiveawayPaymentOption#4184cb88: field store_product_quantity: %w", err) } p.StoreProductQuantity = value default: return b.Skip() } return nil }) } // GetCurrency returns value of Currency field. func (p *PremiumGiveawayPaymentOption) GetCurrency() (value string) { if p == nil { return } return p.Currency } // GetAmount returns value of Amount field. func (p *PremiumGiveawayPaymentOption) GetAmount() (value int64) { if p == nil { return } return p.Amount } // GetWinnerCount returns value of WinnerCount field. func (p *PremiumGiveawayPaymentOption) GetWinnerCount() (value int32) { if p == nil { return } return p.WinnerCount } // GetMonthCount returns value of MonthCount field. func (p *PremiumGiveawayPaymentOption) GetMonthCount() (value int32) { if p == nil { return } return p.MonthCount } // GetStoreProductID returns value of StoreProductID field. func (p *PremiumGiveawayPaymentOption) GetStoreProductID() (value string) { if p == nil { return } return p.StoreProductID } // GetStoreProductQuantity returns value of StoreProductQuantity field. func (p *PremiumGiveawayPaymentOption) GetStoreProductQuantity() (value int32) { if p == nil { return } return p.StoreProductQuantity }