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

// PaymentsGetResaleStarGiftsRequest represents TL type `payments.getResaleStarGifts#7a5fa236`.
// Get collectible gifts¹ of a specific type currently on resale, see here »² for more
// info.
// sort_by_price and sort_by_num are mutually exclusive, if neither are set results are
// sorted by the unixtime (descending) when their resell price was last changed.
// See here »¹ for detailed documentation on this method.
//
// Links:
//  1. https://core.telegram.org/api/gifts#collectible-gifts
//  2. https://core.telegram.org/api/gifts#reselling-collectible-gifts
//  3. https://core.telegram.org/api/gifts#sending-gifts
//
// See https://core.telegram.org/method/payments.getResaleStarGifts for reference.
type PaymentsGetResaleStarGiftsRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Sort gifts by price (ascending).
	SortByPrice bool
	// Sort gifts by number (ascending).
	SortByNum bool
	// Only return collectible gifts that can be bought and used for crafting »¹; render
	// each returned gift's starGiftUnique².craft_chance_permille as its crafting success
	// contribution.
	//
	// Links:
	//  1) https://core.telegram.org/api/gifts#crafting-collectible-gifts
	//  2) https://core.telegram.org/constructor/starGiftUnique
	ForCraft bool
	// Only return gifts that can be bought using Stars¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/stars
	StarsOnly bool
	// If a previous call to the method was made and payments.resaleStarGifts¹
	// attributes_hash was set, pass it here to avoid returning any results if they haven't
	// changed. Otherwise, set this flag and pass 0 to return payments.resaleStarGifts²
	// attributes_hash and payments.resaleStarGifts³.attributes, these two fields will not
	// be set if this flag is not set.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/payments.resaleStarGifts
	//  2) https://core.telegram.org/constructor/payments.resaleStarGifts
	//  3) https://core.telegram.org/constructor/payments.resaleStarGifts
	//
	// Use SetAttributesHash and GetAttributesHash helpers.
	AttributesHash int64
	// Mandatory identifier of the base gift from which the collectible gift was upgraded.
	GiftID int64
	// Optionally filter gifts with the specified attributes. If no attributes of a specific
	// type are specified, all attributes of that type are allowed.
	//
	// Use SetAttributes and GetAttributes helpers.
	Attributes []StarGiftAttributeIDClass
	// Offset for pagination. If not equal to an empty string, payments.resaleStarGifts¹
	// counters will not be set to avoid returning the counters every time a new page is
	// fetched.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/payments.resaleStarGifts
	Offset string
	// Maximum number of results to return, see pagination¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	Limit int
}

// PaymentsGetResaleStarGiftsRequestTypeID is TL type id of PaymentsGetResaleStarGiftsRequest.
const PaymentsGetResaleStarGiftsRequestTypeID = 0x7a5fa236

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

func ( *PaymentsGetResaleStarGiftsRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.SortByPrice == false) {
		return false
	}
	if !(.SortByNum == false) {
		return false
	}
	if !(.ForCraft == false) {
		return false
	}
	if !(.StarsOnly == false) {
		return false
	}
	if !(.AttributesHash == 0) {
		return false
	}
	if !(.GiftID == 0) {
		return false
	}
	if !(.Attributes == nil) {
		return false
	}
	if !(.Offset == "") {
		return false
	}
	if !(.Limit == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsGetResaleStarGiftsRequest from given interface.
func ( *PaymentsGetResaleStarGiftsRequest) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( int64,  bool)
	() ( int64)
	() ( []StarGiftAttributeIDClass,  bool)
	() ( string)
	() ( int)
}) {
	.SortByPrice = .()
	.SortByNum = .()
	.ForCraft = .()
	.StarsOnly = .()
	if ,  := .();  {
		.AttributesHash = 
	}

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

	.Offset = .()
	.Limit = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PaymentsGetResaleStarGiftsRequest) () tdp.Type {
	 := tdp.Type{
		Name: "payments.getResaleStarGifts",
		ID:   PaymentsGetResaleStarGiftsRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "SortByPrice",
			SchemaName: "sort_by_price",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "SortByNum",
			SchemaName: "sort_by_num",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "ForCraft",
			SchemaName: "for_craft",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "StarsOnly",
			SchemaName: "stars_only",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "AttributesHash",
			SchemaName: "attributes_hash",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "GiftID",
			SchemaName: "gift_id",
		},
		{
			Name:       "Attributes",
			SchemaName: "attributes",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Offset",
			SchemaName: "offset",
		},
		{
			Name:       "Limit",
			SchemaName: "limit",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PaymentsGetResaleStarGiftsRequest) () {
	if !(.SortByPrice == false) {
		.Flags.Set(1)
	}
	if !(.SortByNum == false) {
		.Flags.Set(2)
	}
	if !(.ForCraft == false) {
		.Flags.Set(4)
	}
	if !(.StarsOnly == false) {
		.Flags.Set(5)
	}
	if !(.AttributesHash == 0) {
		.Flags.Set(0)
	}
	if !(.Attributes == nil) {
		.Flags.Set(3)
	}
}

// Encode implements bin.Encoder.
func ( *PaymentsGetResaleStarGiftsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.getResaleStarGifts#7a5fa236 as nil")
	}
	.PutID(PaymentsGetResaleStarGiftsRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PaymentsGetResaleStarGiftsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.getResaleStarGifts#7a5fa236 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.getResaleStarGifts#7a5fa236: field flags: %w", )
	}
	if .Flags.Has(0) {
		.PutLong(.AttributesHash)
	}
	.PutLong(.GiftID)
	if .Flags.Has(3) {
		.PutVectorHeader(len(.Attributes))
		for ,  := range .Attributes {
			if  == nil {
				return fmt.Errorf("unable to encode payments.getResaleStarGifts#7a5fa236: field attributes element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode payments.getResaleStarGifts#7a5fa236: field attributes element with index %d: %w", , )
			}
		}
	}
	.PutString(.Offset)
	.PutInt(.Limit)
	return nil
}

// Decode implements bin.Decoder.
func ( *PaymentsGetResaleStarGiftsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.getResaleStarGifts#7a5fa236 to nil")
	}
	if  := .ConsumeID(PaymentsGetResaleStarGiftsRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode payments.getResaleStarGifts#7a5fa236: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *PaymentsGetResaleStarGiftsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.getResaleStarGifts#7a5fa236 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.getResaleStarGifts#7a5fa236: field flags: %w", )
		}
	}
	.SortByPrice = .Flags.Has(1)
	.SortByNum = .Flags.Has(2)
	.ForCraft = .Flags.Has(4)
	.StarsOnly = .Flags.Has(5)
	if .Flags.Has(0) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.getResaleStarGifts#7a5fa236: field attributes_hash: %w", )
		}
		.AttributesHash = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.getResaleStarGifts#7a5fa236: field gift_id: %w", )
		}
		.GiftID = 
	}
	if .Flags.Has(3) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.getResaleStarGifts#7a5fa236: field attributes: %w", )
		}

		if  > 0 {
			.Attributes = make([]StarGiftAttributeIDClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeStarGiftAttributeID()
			if  != nil {
				return fmt.Errorf("unable to decode payments.getResaleStarGifts#7a5fa236: field attributes: %w", )
			}
			.Attributes = append(.Attributes, )
		}
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode payments.getResaleStarGifts#7a5fa236: field offset: %w", )
		}
		.Offset = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode payments.getResaleStarGifts#7a5fa236: field limit: %w", )
		}
		.Limit = 
	}
	return nil
}

// SetSortByPrice sets value of SortByPrice conditional field.
func ( *PaymentsGetResaleStarGiftsRequest) ( bool) {
	if  {
		.Flags.Set(1)
		.SortByPrice = true
	} else {
		.Flags.Unset(1)
		.SortByPrice = false
	}
}

// GetSortByPrice returns value of SortByPrice conditional field.
func ( *PaymentsGetResaleStarGiftsRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetSortByNum sets value of SortByNum conditional field.
func ( *PaymentsGetResaleStarGiftsRequest) ( bool) {
	if  {
		.Flags.Set(2)
		.SortByNum = true
	} else {
		.Flags.Unset(2)
		.SortByNum = false
	}
}

// GetSortByNum returns value of SortByNum conditional field.
func ( *PaymentsGetResaleStarGiftsRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetForCraft sets value of ForCraft conditional field.
func ( *PaymentsGetResaleStarGiftsRequest) ( bool) {
	if  {
		.Flags.Set(4)
		.ForCraft = true
	} else {
		.Flags.Unset(4)
		.ForCraft = false
	}
}

// GetForCraft returns value of ForCraft conditional field.
func ( *PaymentsGetResaleStarGiftsRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(4)
}

// SetStarsOnly sets value of StarsOnly conditional field.
func ( *PaymentsGetResaleStarGiftsRequest) ( bool) {
	if  {
		.Flags.Set(5)
		.StarsOnly = true
	} else {
		.Flags.Unset(5)
		.StarsOnly = false
	}
}

// GetStarsOnly returns value of StarsOnly conditional field.
func ( *PaymentsGetResaleStarGiftsRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(5)
}

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

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

// GetGiftID returns value of GiftID field.
func ( *PaymentsGetResaleStarGiftsRequest) () ( int64) {
	if  == nil {
		return
	}
	return .GiftID
}

// SetAttributes sets value of Attributes conditional field.
func ( *PaymentsGetResaleStarGiftsRequest) ( []StarGiftAttributeIDClass) {
	.Flags.Set(3)
	.Attributes = 
}

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

// GetOffset returns value of Offset field.
func ( *PaymentsGetResaleStarGiftsRequest) () ( string) {
	if  == nil {
		return
	}
	return .Offset
}

// GetLimit returns value of Limit field.
func ( *PaymentsGetResaleStarGiftsRequest) () ( int) {
	if  == nil {
		return
	}
	return .Limit
}

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

// PaymentsGetResaleStarGifts invokes method payments.getResaleStarGifts#7a5fa236 returning error if any.
// Get collectible gifts¹ of a specific type currently on resale, see here »² for more
// info.
// sort_by_price and sort_by_num are mutually exclusive, if neither are set results are
// sorted by the unixtime (descending) when their resell price was last changed.
// See here »¹ for detailed documentation on this method.
//
// Links:
//  1. https://core.telegram.org/api/gifts#collectible-gifts
//  2. https://core.telegram.org/api/gifts#reselling-collectible-gifts
//  3. https://core.telegram.org/api/gifts#sending-gifts
//
// Possible errors:
//
//	400 STARGIFT_ATTRIBUTE_INVALID:
//	400 STARGIFT_INVALID: The passed gift is invalid.
//
// See https://core.telegram.org/method/payments.getResaleStarGifts for reference.
func ( *Client) ( context.Context,  *PaymentsGetResaleStarGiftsRequest) (*PaymentsResaleStarGifts, error) {
	var  PaymentsResaleStarGifts

	if  := .rpc.Invoke(, , &);  != nil {
		return nil, 
	}
	return &, nil
}