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

// PaymentsResaleStarGifts represents TL type `payments.resaleStarGifts#947a12df`.
// List of gifts currently on resale »¹.
//
// Links:
//  1. https://core.telegram.org/api/gifts#reselling-collectible-gifts
//
// See https://core.telegram.org/constructor/payments.resaleStarGifts for reference.
type PaymentsResaleStarGifts struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Total number of results.
	Count int
	// Collectible gifts on resale (may be less than count, in which case next_offset will be
	// set).
	Gifts []StarGiftClass
	// Offset for pagination, pass this to payments.getResaleStarGifts¹.offset to fetch the
	// next results.
	//
	// Links:
	//  1) https://core.telegram.org/method/payments.getResaleStarGifts
	//
	// Use SetNextOffset and GetNextOffset helpers.
	NextOffset string
	// Possible gift attributes, only set if payments.getResaleStarGifts¹.attributes_hash is
	// set (on the first call, it must be equal to 0).
	//
	// Links:
	//  1) https://core.telegram.org/method/payments.getResaleStarGifts
	//
	// Use SetAttributes and GetAttributes helpers.
	Attributes []StarGiftAttributeClass
	// Hash of the attributes field, pass this to payments.getResaleStarGifts¹
	// attributes_hash to avoid returning any attributes (flag not set) if they haven't
	// changed.
	//
	// Links:
	//  1) https://core.telegram.org/method/payments.getResaleStarGifts
	//
	// Use SetAttributesHash and GetAttributesHash helpers.
	AttributesHash int64
	// Chats mentioned in the attributes.
	Chats []ChatClass
	// Indicates the total number of gifts that have a specific attribute, only set if
	// payments.getResaleStarGifts¹.offset is empty (since this field is not related to the
	// current result page but to all of them, it's only returned on the first page).
	//
	// Links:
	//  1) https://core.telegram.org/method/payments.getResaleStarGifts
	//
	// Use SetCounters and GetCounters helpers.
	Counters []StarGiftAttributeCounter
	// Users mentioned in the attributes.
	Users []UserClass
}

// PaymentsResaleStarGiftsTypeID is TL type id of PaymentsResaleStarGifts.
const PaymentsResaleStarGiftsTypeID = 0x947a12df

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

func ( *PaymentsResaleStarGifts) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Count == 0) {
		return false
	}
	if !(.Gifts == nil) {
		return false
	}
	if !(.NextOffset == "") {
		return false
	}
	if !(.Attributes == nil) {
		return false
	}
	if !(.AttributesHash == 0) {
		return false
	}
	if !(.Chats == nil) {
		return false
	}
	if !(.Counters == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsResaleStarGifts from given interface.
func ( *PaymentsResaleStarGifts) ( interface {
	() ( int)
	() ( []StarGiftClass)
	() ( string,  bool)
	() ( []StarGiftAttributeClass,  bool)
	() ( int64,  bool)
	() ( []ChatClass)
	() ( []StarGiftAttributeCounter,  bool)
	() ( []UserClass)
}) {
	.Count = .()
	.Gifts = .()
	if ,  := .();  {
		.NextOffset = 
	}

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

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

	.Chats = .()
	if ,  := .();  {
		.Counters = 
	}

	.Users = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PaymentsResaleStarGifts) () tdp.Type {
	 := tdp.Type{
		Name: "payments.resaleStarGifts",
		ID:   PaymentsResaleStarGiftsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Count",
			SchemaName: "count",
		},
		{
			Name:       "Gifts",
			SchemaName: "gifts",
		},
		{
			Name:       "NextOffset",
			SchemaName: "next_offset",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Attributes",
			SchemaName: "attributes",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "AttributesHash",
			SchemaName: "attributes_hash",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Counters",
			SchemaName: "counters",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PaymentsResaleStarGifts) () {
	if !(.NextOffset == "") {
		.Flags.Set(0)
	}
	if !(.Attributes == nil) {
		.Flags.Set(1)
	}
	if !(.AttributesHash == 0) {
		.Flags.Set(1)
	}
	if !(.Counters == nil) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *PaymentsResaleStarGifts) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.resaleStarGifts#947a12df as nil")
	}
	.PutID(PaymentsResaleStarGiftsTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PaymentsResaleStarGifts) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.resaleStarGifts#947a12df as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.resaleStarGifts#947a12df: field flags: %w", )
	}
	.PutInt(.Count)
	.PutVectorHeader(len(.Gifts))
	for ,  := range .Gifts {
		if  == nil {
			return fmt.Errorf("unable to encode payments.resaleStarGifts#947a12df: field gifts element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode payments.resaleStarGifts#947a12df: field gifts element with index %d: %w", , )
		}
	}
	if .Flags.Has(0) {
		.PutString(.NextOffset)
	}
	if .Flags.Has(1) {
		.PutVectorHeader(len(.Attributes))
		for ,  := range .Attributes {
			if  == nil {
				return fmt.Errorf("unable to encode payments.resaleStarGifts#947a12df: field attributes element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode payments.resaleStarGifts#947a12df: field attributes element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(1) {
		.PutLong(.AttributesHash)
	}
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode payments.resaleStarGifts#947a12df: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode payments.resaleStarGifts#947a12df: field chats element with index %d: %w", , )
		}
	}
	if .Flags.Has(2) {
		.PutVectorHeader(len(.Counters))
		for ,  := range .Counters {
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode payments.resaleStarGifts#947a12df: field counters element with index %d: %w", , )
			}
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode payments.resaleStarGifts#947a12df: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode payments.resaleStarGifts#947a12df: field users element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *PaymentsResaleStarGifts) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.resaleStarGifts#947a12df to nil")
	}
	if  := .ConsumeID(PaymentsResaleStarGiftsTypeID);  != nil {
		return fmt.Errorf("unable to decode payments.resaleStarGifts#947a12df: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *PaymentsResaleStarGifts) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.resaleStarGifts#947a12df to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.resaleStarGifts#947a12df: field flags: %w", )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode payments.resaleStarGifts#947a12df: field count: %w", )
		}
		.Count = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.resaleStarGifts#947a12df: field gifts: %w", )
		}

		if  > 0 {
			.Gifts = make([]StarGiftClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeStarGift()
			if  != nil {
				return fmt.Errorf("unable to decode payments.resaleStarGifts#947a12df: field gifts: %w", )
			}
			.Gifts = append(.Gifts, )
		}
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode payments.resaleStarGifts#947a12df: field next_offset: %w", )
		}
		.NextOffset = 
	}
	if .Flags.Has(1) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.resaleStarGifts#947a12df: field attributes: %w", )
		}

		if  > 0 {
			.Attributes = make([]StarGiftAttributeClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeStarGiftAttribute()
			if  != nil {
				return fmt.Errorf("unable to decode payments.resaleStarGifts#947a12df: field attributes: %w", )
			}
			.Attributes = append(.Attributes, )
		}
	}
	if .Flags.Has(1) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.resaleStarGifts#947a12df: field attributes_hash: %w", )
		}
		.AttributesHash = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.resaleStarGifts#947a12df: field chats: %w", )
		}

		if  > 0 {
			.Chats = make([]ChatClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeChat()
			if  != nil {
				return fmt.Errorf("unable to decode payments.resaleStarGifts#947a12df: field chats: %w", )
			}
			.Chats = append(.Chats, )
		}
	}
	if .Flags.Has(2) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.resaleStarGifts#947a12df: field counters: %w", )
		}

		if  > 0 {
			.Counters = make([]StarGiftAttributeCounter, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  StarGiftAttributeCounter
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode payments.resaleStarGifts#947a12df: field counters: %w", )
			}
			.Counters = append(.Counters, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.resaleStarGifts#947a12df: field users: %w", )
		}

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

// GetCount returns value of Count field.
func ( *PaymentsResaleStarGifts) () ( int) {
	if  == nil {
		return
	}
	return .Count
}

// GetGifts returns value of Gifts field.
func ( *PaymentsResaleStarGifts) () ( []StarGiftClass) {
	if  == nil {
		return
	}
	return .Gifts
}

// SetNextOffset sets value of NextOffset conditional field.
func ( *PaymentsResaleStarGifts) ( string) {
	.Flags.Set(0)
	.NextOffset = 
}

// GetNextOffset returns value of NextOffset conditional field and
// boolean which is true if field was set.
func ( *PaymentsResaleStarGifts) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .NextOffset, true
}

// SetAttributes sets value of Attributes conditional field.
func ( *PaymentsResaleStarGifts) ( []StarGiftAttributeClass) {
	.Flags.Set(1)
	.Attributes = 
}

// GetAttributes returns value of Attributes conditional field and
// boolean which is true if field was set.
func ( *PaymentsResaleStarGifts) () ( []StarGiftAttributeClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Attributes, true
}

// SetAttributesHash sets value of AttributesHash conditional field.
func ( *PaymentsResaleStarGifts) ( int64) {
	.Flags.Set(1)
	.AttributesHash = 
}

// GetAttributesHash returns value of AttributesHash conditional field and
// boolean which is true if field was set.
func ( *PaymentsResaleStarGifts) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .AttributesHash, true
}

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

// SetCounters sets value of Counters conditional field.
func ( *PaymentsResaleStarGifts) ( []StarGiftAttributeCounter) {
	.Flags.Set(2)
	.Counters = 
}

// GetCounters returns value of Counters conditional field and
// boolean which is true if field was set.
func ( *PaymentsResaleStarGifts) () ( []StarGiftAttributeCounter,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .Counters, true
}

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

// MapGifts returns field Gifts wrapped in StarGiftClassArray helper.
func ( *PaymentsResaleStarGifts) () ( StarGiftClassArray) {
	return StarGiftClassArray(.Gifts)
}

// MapAttributes returns field Attributes wrapped in StarGiftAttributeClassArray helper.
func ( *PaymentsResaleStarGifts) () ( StarGiftAttributeClassArray,  bool) {
	if !.Flags.Has(1) {
		return , false
	}
	return StarGiftAttributeClassArray(.Attributes), true
}

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

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