// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	
	
	
	
	

	

	
	
	
	
)

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

// PaymentsCheckedGiftCode represents TL type `payments.checkedGiftCode#284a1096`.
// Contains info about a Telegram Premium giftcode link¹.
//
// Links:
//  1. https://core.telegram.org/api/links#premium-giftcode-links
//
// See https://core.telegram.org/constructor/payments.checkedGiftCode for reference.
type PaymentsCheckedGiftCode struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether this giftcode was created by a giveaway¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/giveaways
	ViaGiveaway bool
	// The peer that created the gift code.
	//
	// Use SetFromID and GetFromID helpers.
	FromID PeerClass
	// Message ID of the giveaway in the channel specified in from_id.
	//
	// Use SetGiveawayMsgID and GetGiveawayMsgID helpers.
	GiveawayMsgID int
	// The destination user of the gift.
	//
	// Use SetToID and GetToID helpers.
	ToID int64
	// Creation date of the gift code.
	Date int
	// Duration in months of the gifted Telegram Premium¹ subscription.
	//
	// Links:
	//  1) https://core.telegram.org/api/premium
	Months int
	// When was the giftcode imported, if it was imported.
	//
	// Use SetUsedDate and GetUsedDate helpers.
	UsedDate int
	// Mentioned chats
	Chats []ChatClass
	// Mentioned users
	Users []UserClass
}

// PaymentsCheckedGiftCodeTypeID is TL type id of PaymentsCheckedGiftCode.
const PaymentsCheckedGiftCodeTypeID = 0x284a1096

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

func ( *PaymentsCheckedGiftCode) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.ViaGiveaway == false) {
		return false
	}
	if !(.FromID == nil) {
		return false
	}
	if !(.GiveawayMsgID == 0) {
		return false
	}
	if !(.ToID == 0) {
		return false
	}
	if !(.Date == 0) {
		return false
	}
	if !(.Months == 0) {
		return false
	}
	if !(.UsedDate == 0) {
		return false
	}
	if !(.Chats == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsCheckedGiftCode from given interface.
func ( *PaymentsCheckedGiftCode) ( interface {
	() ( bool)
	() ( PeerClass,  bool)
	() ( int,  bool)
	() ( int64,  bool)
	() ( int)
	() ( int)
	() ( int,  bool)
	() ( []ChatClass)
	() ( []UserClass)
}) {
	.ViaGiveaway = .()
	if ,  := .();  {
		.FromID = 
	}

	if ,  := .();  {
		.GiveawayMsgID = 
	}

	if ,  := .();  {
		.ToID = 
	}

	.Date = .()
	.Months = .()
	if ,  := .();  {
		.UsedDate = 
	}

	.Chats = .()
	.Users = .()
}

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

// TypeName returns name of type in TL schema.
func (*PaymentsCheckedGiftCode) () string {
	return "payments.checkedGiftCode"
}

// TypeInfo returns info about TL type.
func ( *PaymentsCheckedGiftCode) () tdp.Type {
	 := tdp.Type{
		Name: "payments.checkedGiftCode",
		ID:   PaymentsCheckedGiftCodeTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "ViaGiveaway",
			SchemaName: "via_giveaway",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "FromID",
			SchemaName: "from_id",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "GiveawayMsgID",
			SchemaName: "giveaway_msg_id",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "ToID",
			SchemaName: "to_id",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
		{
			Name:       "Months",
			SchemaName: "months",
		},
		{
			Name:       "UsedDate",
			SchemaName: "used_date",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PaymentsCheckedGiftCode) () {
	if !(.ViaGiveaway == false) {
		.Flags.Set(2)
	}
	if !(.FromID == nil) {
		.Flags.Set(4)
	}
	if !(.GiveawayMsgID == 0) {
		.Flags.Set(3)
	}
	if !(.ToID == 0) {
		.Flags.Set(0)
	}
	if !(.UsedDate == 0) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *PaymentsCheckedGiftCode) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.checkedGiftCode#284a1096 as nil")
	}
	.PutID(PaymentsCheckedGiftCodeTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PaymentsCheckedGiftCode) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.checkedGiftCode#284a1096 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.checkedGiftCode#284a1096: field flags: %w", )
	}
	if .Flags.Has(4) {
		if .FromID == nil {
			return fmt.Errorf("unable to encode payments.checkedGiftCode#284a1096: field from_id is nil")
		}
		if  := .FromID.Encode();  != nil {
			return fmt.Errorf("unable to encode payments.checkedGiftCode#284a1096: field from_id: %w", )
		}
	}
	if .Flags.Has(3) {
		.PutInt(.GiveawayMsgID)
	}
	if .Flags.Has(0) {
		.PutLong(.ToID)
	}
	.PutInt(.Date)
	.PutInt(.Months)
	if .Flags.Has(1) {
		.PutInt(.UsedDate)
	}
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode payments.checkedGiftCode#284a1096: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode payments.checkedGiftCode#284a1096: field chats element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode payments.checkedGiftCode#284a1096: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode payments.checkedGiftCode#284a1096: field users element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *PaymentsCheckedGiftCode) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.checkedGiftCode#284a1096 to nil")
	}
	if  := .ConsumeID(PaymentsCheckedGiftCodeTypeID);  != nil {
		return fmt.Errorf("unable to decode payments.checkedGiftCode#284a1096: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *PaymentsCheckedGiftCode) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.checkedGiftCode#284a1096 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.checkedGiftCode#284a1096: field flags: %w", )
		}
	}
	.ViaGiveaway = .Flags.Has(2)
	if .Flags.Has(4) {
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode payments.checkedGiftCode#284a1096: field from_id: %w", )
		}
		.FromID = 
	}
	if .Flags.Has(3) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode payments.checkedGiftCode#284a1096: field giveaway_msg_id: %w", )
		}
		.GiveawayMsgID = 
	}
	if .Flags.Has(0) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.checkedGiftCode#284a1096: field to_id: %w", )
		}
		.ToID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode payments.checkedGiftCode#284a1096: field date: %w", )
		}
		.Date = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode payments.checkedGiftCode#284a1096: field months: %w", )
		}
		.Months = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode payments.checkedGiftCode#284a1096: field used_date: %w", )
		}
		.UsedDate = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.checkedGiftCode#284a1096: field chats: %w", )
		}

		if  > 0 {
			.Chats = make([]ChatClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeChat()
			if  != nil {
				return fmt.Errorf("unable to decode payments.checkedGiftCode#284a1096: field chats: %w", )
			}
			.Chats = append(.Chats, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.checkedGiftCode#284a1096: field users: %w", )
		}

		if  > 0 {
			.Users = make([]UserClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeUser()
			if  != nil {
				return fmt.Errorf("unable to decode payments.checkedGiftCode#284a1096: field users: %w", )
			}
			.Users = append(.Users, )
		}
	}
	return nil
}

// SetViaGiveaway sets value of ViaGiveaway conditional field.
func ( *PaymentsCheckedGiftCode) ( bool) {
	if  {
		.Flags.Set(2)
		.ViaGiveaway = true
	} else {
		.Flags.Unset(2)
		.ViaGiveaway = false
	}
}

// GetViaGiveaway returns value of ViaGiveaway conditional field.
func ( *PaymentsCheckedGiftCode) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetFromID sets value of FromID conditional field.
func ( *PaymentsCheckedGiftCode) ( PeerClass) {
	.Flags.Set(4)
	.FromID = 
}

// GetFromID returns value of FromID conditional field and
// boolean which is true if field was set.
func ( *PaymentsCheckedGiftCode) () ( PeerClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .FromID, true
}

// SetGiveawayMsgID sets value of GiveawayMsgID conditional field.
func ( *PaymentsCheckedGiftCode) ( int) {
	.Flags.Set(3)
	.GiveawayMsgID = 
}

// GetGiveawayMsgID returns value of GiveawayMsgID conditional field and
// boolean which is true if field was set.
func ( *PaymentsCheckedGiftCode) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .GiveawayMsgID, true
}

// SetToID sets value of ToID conditional field.
func ( *PaymentsCheckedGiftCode) ( int64) {
	.Flags.Set(0)
	.ToID = 
}

// GetToID returns value of ToID conditional field and
// boolean which is true if field was set.
func ( *PaymentsCheckedGiftCode) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .ToID, true
}

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

// GetMonths returns value of Months field.
func ( *PaymentsCheckedGiftCode) () ( int) {
	if  == nil {
		return
	}
	return .Months
}

// SetUsedDate sets value of UsedDate conditional field.
func ( *PaymentsCheckedGiftCode) ( int) {
	.Flags.Set(1)
	.UsedDate = 
}

// GetUsedDate returns value of UsedDate conditional field and
// boolean which is true if field was set.
func ( *PaymentsCheckedGiftCode) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .UsedDate, true
}

// GetChats returns value of Chats field.
func ( *PaymentsCheckedGiftCode) () ( []ChatClass) {
	if  == nil {
		return
	}
	return .Chats
}

// GetUsers returns value of Users field.
func ( *PaymentsCheckedGiftCode) () ( []UserClass) {
	if  == nil {
		return
	}
	return .Users
}

// MapChats returns field Chats wrapped in ChatClassArray helper.
func ( *PaymentsCheckedGiftCode) () ( ChatClassArray) {
	return ChatClassArray(.Chats)
}

// MapUsers returns field Users wrapped in UserClassArray helper.
func ( *PaymentsCheckedGiftCode) () ( UserClassArray) {
	return UserClassArray(.Users)
}