// 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{} ) // PremiumGiftCodeInfo represents TL type `premiumGiftCodeInfo#b88fa8de`. type PremiumGiftCodeInfo struct { // Identifier of a chat or a user that created the gift code; may be null if unknown. If // null and the code is from messagePremiumGiftCode message, then creator_id from the // message can be used CreatorID MessageSenderClass // Point in time (Unix timestamp) when the code was created CreationDate int32 // True, if the gift code was created for a giveaway IsFromGiveaway bool // Identifier of the corresponding giveaway message in the creator_id chat; can be 0 or // an identifier of a deleted message GiveawayMessageID int64 // Number of months the Telegram Premium subscription will be active after code // activation MonthCount int32 // Identifier of a user for which the code was created; 0 if none UserID int64 // Point in time (Unix timestamp) when the code was activated; 0 if none UseDate int32 } // PremiumGiftCodeInfoTypeID is TL type id of PremiumGiftCodeInfo. const PremiumGiftCodeInfoTypeID = 0xb88fa8de // Ensuring interfaces in compile-time for PremiumGiftCodeInfo. var ( _ bin.Encoder = &PremiumGiftCodeInfo{} _ bin.Decoder = &PremiumGiftCodeInfo{} _ bin.BareEncoder = &PremiumGiftCodeInfo{} _ bin.BareDecoder = &PremiumGiftCodeInfo{} ) func (p *PremiumGiftCodeInfo) Zero() bool { if p == nil { return true } if !(p.CreatorID == nil) { return false } if !(p.CreationDate == 0) { return false } if !(p.IsFromGiveaway == false) { return false } if !(p.GiveawayMessageID == 0) { return false } if !(p.MonthCount == 0) { return false } if !(p.UserID == 0) { return false } if !(p.UseDate == 0) { return false } return true } // String implements fmt.Stringer. func (p *PremiumGiftCodeInfo) String() string { if p == nil { return "PremiumGiftCodeInfo(nil)" } type Alias PremiumGiftCodeInfo return fmt.Sprintf("PremiumGiftCodeInfo%+v", Alias(*p)) } // TypeID returns type id in TL schema. // // See https://core.telegram.org/mtproto/TL-tl#remarks. func (*PremiumGiftCodeInfo) TypeID() uint32 { return PremiumGiftCodeInfoTypeID } // TypeName returns name of type in TL schema. func (*PremiumGiftCodeInfo) TypeName() string { return "premiumGiftCodeInfo" } // TypeInfo returns info about TL type. func (p *PremiumGiftCodeInfo) TypeInfo() tdp.Type { typ := tdp.Type{ Name: "premiumGiftCodeInfo", ID: PremiumGiftCodeInfoTypeID, } if p == nil { typ.Null = true return typ } typ.Fields = []tdp.Field{ { Name: "CreatorID", SchemaName: "creator_id", }, { Name: "CreationDate", SchemaName: "creation_date", }, { Name: "IsFromGiveaway", SchemaName: "is_from_giveaway", }, { Name: "GiveawayMessageID", SchemaName: "giveaway_message_id", }, { Name: "MonthCount", SchemaName: "month_count", }, { Name: "UserID", SchemaName: "user_id", }, { Name: "UseDate", SchemaName: "use_date", }, } return typ } // Encode implements bin.Encoder. func (p *PremiumGiftCodeInfo) Encode(b *bin.Buffer) error { if p == nil { return fmt.Errorf("can't encode premiumGiftCodeInfo#b88fa8de as nil") } b.PutID(PremiumGiftCodeInfoTypeID) return p.EncodeBare(b) } // EncodeBare implements bin.BareEncoder. func (p *PremiumGiftCodeInfo) EncodeBare(b *bin.Buffer) error { if p == nil { return fmt.Errorf("can't encode premiumGiftCodeInfo#b88fa8de as nil") } if p.CreatorID == nil { return fmt.Errorf("unable to encode premiumGiftCodeInfo#b88fa8de: field creator_id is nil") } if err := p.CreatorID.Encode(b); err != nil { return fmt.Errorf("unable to encode premiumGiftCodeInfo#b88fa8de: field creator_id: %w", err) } b.PutInt32(p.CreationDate) b.PutBool(p.IsFromGiveaway) b.PutInt53(p.GiveawayMessageID) b.PutInt32(p.MonthCount) b.PutInt53(p.UserID) b.PutInt32(p.UseDate) return nil } // Decode implements bin.Decoder. func (p *PremiumGiftCodeInfo) Decode(b *bin.Buffer) error { if p == nil { return fmt.Errorf("can't decode premiumGiftCodeInfo#b88fa8de to nil") } if err := b.ConsumeID(PremiumGiftCodeInfoTypeID); err != nil { return fmt.Errorf("unable to decode premiumGiftCodeInfo#b88fa8de: %w", err) } return p.DecodeBare(b) } // DecodeBare implements bin.BareDecoder. func (p *PremiumGiftCodeInfo) DecodeBare(b *bin.Buffer) error { if p == nil { return fmt.Errorf("can't decode premiumGiftCodeInfo#b88fa8de to nil") } { value, err := DecodeMessageSender(b) if err != nil { return fmt.Errorf("unable to decode premiumGiftCodeInfo#b88fa8de: field creator_id: %w", err) } p.CreatorID = value } { value, err := b.Int32() if err != nil { return fmt.Errorf("unable to decode premiumGiftCodeInfo#b88fa8de: field creation_date: %w", err) } p.CreationDate = value } { value, err := b.Bool() if err != nil { return fmt.Errorf("unable to decode premiumGiftCodeInfo#b88fa8de: field is_from_giveaway: %w", err) } p.IsFromGiveaway = value } { value, err := b.Int53() if err != nil { return fmt.Errorf("unable to decode premiumGiftCodeInfo#b88fa8de: field giveaway_message_id: %w", err) } p.GiveawayMessageID = value } { value, err := b.Int32() if err != nil { return fmt.Errorf("unable to decode premiumGiftCodeInfo#b88fa8de: field month_count: %w", err) } p.MonthCount = value } { value, err := b.Int53() if err != nil { return fmt.Errorf("unable to decode premiumGiftCodeInfo#b88fa8de: field user_id: %w", err) } p.UserID = value } { value, err := b.Int32() if err != nil { return fmt.Errorf("unable to decode premiumGiftCodeInfo#b88fa8de: field use_date: %w", err) } p.UseDate = value } return nil } // EncodeTDLibJSON implements tdjson.TDLibEncoder. func (p *PremiumGiftCodeInfo) EncodeTDLibJSON(b tdjson.Encoder) error { if p == nil { return fmt.Errorf("can't encode premiumGiftCodeInfo#b88fa8de as nil") } b.ObjStart() b.PutID("premiumGiftCodeInfo") b.Comma() b.FieldStart("creator_id") if p.CreatorID == nil { return fmt.Errorf("unable to encode premiumGiftCodeInfo#b88fa8de: field creator_id is nil") } if err := p.CreatorID.EncodeTDLibJSON(b); err != nil { return fmt.Errorf("unable to encode premiumGiftCodeInfo#b88fa8de: field creator_id: %w", err) } b.Comma() b.FieldStart("creation_date") b.PutInt32(p.CreationDate) b.Comma() b.FieldStart("is_from_giveaway") b.PutBool(p.IsFromGiveaway) b.Comma() b.FieldStart("giveaway_message_id") b.PutInt53(p.GiveawayMessageID) b.Comma() b.FieldStart("month_count") b.PutInt32(p.MonthCount) b.Comma() b.FieldStart("user_id") b.PutInt53(p.UserID) b.Comma() b.FieldStart("use_date") b.PutInt32(p.UseDate) b.Comma() b.StripComma() b.ObjEnd() return nil } // DecodeTDLibJSON implements tdjson.TDLibDecoder. func (p *PremiumGiftCodeInfo) DecodeTDLibJSON(b tdjson.Decoder) error { if p == nil { return fmt.Errorf("can't decode premiumGiftCodeInfo#b88fa8de to nil") } return b.Obj(func(b tdjson.Decoder, key []byte) error { switch string(key) { case tdjson.TypeField: if err := b.ConsumeID("premiumGiftCodeInfo"); err != nil { return fmt.Errorf("unable to decode premiumGiftCodeInfo#b88fa8de: %w", err) } case "creator_id": value, err := DecodeTDLibJSONMessageSender(b) if err != nil { return fmt.Errorf("unable to decode premiumGiftCodeInfo#b88fa8de: field creator_id: %w", err) } p.CreatorID = value case "creation_date": value, err := b.Int32() if err != nil { return fmt.Errorf("unable to decode premiumGiftCodeInfo#b88fa8de: field creation_date: %w", err) } p.CreationDate = value case "is_from_giveaway": value, err := b.Bool() if err != nil { return fmt.Errorf("unable to decode premiumGiftCodeInfo#b88fa8de: field is_from_giveaway: %w", err) } p.IsFromGiveaway = value case "giveaway_message_id": value, err := b.Int53() if err != nil { return fmt.Errorf("unable to decode premiumGiftCodeInfo#b88fa8de: field giveaway_message_id: %w", err) } p.GiveawayMessageID = value case "month_count": value, err := b.Int32() if err != nil { return fmt.Errorf("unable to decode premiumGiftCodeInfo#b88fa8de: field month_count: %w", err) } p.MonthCount = value case "user_id": value, err := b.Int53() if err != nil { return fmt.Errorf("unable to decode premiumGiftCodeInfo#b88fa8de: field user_id: %w", err) } p.UserID = value case "use_date": value, err := b.Int32() if err != nil { return fmt.Errorf("unable to decode premiumGiftCodeInfo#b88fa8de: field use_date: %w", err) } p.UseDate = value default: return b.Skip() } return nil }) } // GetCreatorID returns value of CreatorID field. func (p *PremiumGiftCodeInfo) GetCreatorID() (value MessageSenderClass) { if p == nil { return } return p.CreatorID } // GetCreationDate returns value of CreationDate field. func (p *PremiumGiftCodeInfo) GetCreationDate() (value int32) { if p == nil { return } return p.CreationDate } // GetIsFromGiveaway returns value of IsFromGiveaway field. func (p *PremiumGiftCodeInfo) GetIsFromGiveaway() (value bool) { if p == nil { return } return p.IsFromGiveaway } // GetGiveawayMessageID returns value of GiveawayMessageID field. func (p *PremiumGiftCodeInfo) GetGiveawayMessageID() (value int64) { if p == nil { return } return p.GiveawayMessageID } // GetMonthCount returns value of MonthCount field. func (p *PremiumGiftCodeInfo) GetMonthCount() (value int32) { if p == nil { return } return p.MonthCount } // GetUserID returns value of UserID field. func (p *PremiumGiftCodeInfo) GetUserID() (value int64) { if p == nil { return } return p.UserID } // GetUseDate returns value of UseDate field. func (p *PremiumGiftCodeInfo) GetUseDate() (value int32) { if p == nil { return } return p.UseDate }