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

// PaymentsUniqueStarGiftValueInfo represents TL type `payments.uniqueStarGiftValueInfo#512fe446`.
// Information about the value of a collectible gift »¹.
//
// Links:
//  1. https://core.telegram.org/api/gifts#collectible-gifts
//
// See https://core.telegram.org/constructor/payments.uniqueStarGiftValueInfo for reference.
type PaymentsUniqueStarGiftValueInfo struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If set, the last sale was completed on Fragment.
	LastSaleOnFragment bool
	// If set, the value is calculated from the average value of sold gifts of the same type.
	// Otherwise, it is based on the sale price of the gift.
	ValueIsAverage bool
	// Three-letter ISO 4217 currency¹ code (a localized fiat currency used to represent
	// prices and price estimations in this constructor).
	//
	// Links:
	//  1) https://core.telegram.org/bots/payments#supported-currencies
	Currency string
	// Estimated value of the gift, in the smallest unit of the currency specified in
	// currency.
	Value int64
	// Initial purchase date of the gift.
	InitialSaleDate int
	// Initial purchase price in Stars.
	InitialSaleStars int64
	// Initial purchase price in the smallest unit of the currency specified in currency
	// (automatically converted from initial_sale_stars).
	InitialSalePrice int64
	// Last resale date of the gift.
	//
	// Use SetLastSaleDate and GetLastSaleDate helpers.
	LastSaleDate int
	// Last resale price, in the smallest unit of the currency specified in currency.
	//
	// Use SetLastSalePrice and GetLastSalePrice helpers.
	LastSalePrice int64
	// The current minimum price of collectible gifts of the same type, in the smallest unit
	// of the currency specified in currency.
	//
	// Use SetFloorPrice and GetFloorPrice helpers.
	FloorPrice int64
	// The current average sale price of collectible gifts of the same type, in the smallest
	// unit of the currency specified in currency.
	//
	// Use SetAveragePrice and GetAveragePrice helpers.
	AveragePrice int64
	// Number of gifts of the same type currently being resold on Telegram.
	//
	// Use SetListedCount and GetListedCount helpers.
	ListedCount int
	// Number of gifts of the same type currently being resold on fragment.
	//
	// Use SetFragmentListedCount and GetFragmentListedCount helpers.
	FragmentListedCount int
	// Fragment link to the listing of gifts of the same type currently being resold on
	// fragment.
	//
	// Use SetFragmentListedURL and GetFragmentListedURL helpers.
	FragmentListedURL string
}

// PaymentsUniqueStarGiftValueInfoTypeID is TL type id of PaymentsUniqueStarGiftValueInfo.
const PaymentsUniqueStarGiftValueInfoTypeID = 0x512fe446

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

func ( *PaymentsUniqueStarGiftValueInfo) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.LastSaleOnFragment == false) {
		return false
	}
	if !(.ValueIsAverage == false) {
		return false
	}
	if !(.Currency == "") {
		return false
	}
	if !(.Value == 0) {
		return false
	}
	if !(.InitialSaleDate == 0) {
		return false
	}
	if !(.InitialSaleStars == 0) {
		return false
	}
	if !(.InitialSalePrice == 0) {
		return false
	}
	if !(.LastSaleDate == 0) {
		return false
	}
	if !(.LastSalePrice == 0) {
		return false
	}
	if !(.FloorPrice == 0) {
		return false
	}
	if !(.AveragePrice == 0) {
		return false
	}
	if !(.ListedCount == 0) {
		return false
	}
	if !(.FragmentListedCount == 0) {
		return false
	}
	if !(.FragmentListedURL == "") {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsUniqueStarGiftValueInfo from given interface.
func ( *PaymentsUniqueStarGiftValueInfo) ( interface {
	() ( bool)
	() ( bool)
	() ( string)
	() ( int64)
	() ( int)
	() ( int64)
	() ( int64)
	() ( int,  bool)
	() ( int64,  bool)
	() ( int64,  bool)
	() ( int64,  bool)
	() ( int,  bool)
	() ( int,  bool)
	() ( string,  bool)
}) {
	.LastSaleOnFragment = .()
	.ValueIsAverage = .()
	.Currency = .()
	.Value = .()
	.InitialSaleDate = .()
	.InitialSaleStars = .()
	.InitialSalePrice = .()
	if ,  := .();  {
		.LastSaleDate = 
	}

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

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

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

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

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *PaymentsUniqueStarGiftValueInfo) () tdp.Type {
	 := tdp.Type{
		Name: "payments.uniqueStarGiftValueInfo",
		ID:   PaymentsUniqueStarGiftValueInfoTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "LastSaleOnFragment",
			SchemaName: "last_sale_on_fragment",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "ValueIsAverage",
			SchemaName: "value_is_average",
			Null:       !.Flags.Has(6),
		},
		{
			Name:       "Currency",
			SchemaName: "currency",
		},
		{
			Name:       "Value",
			SchemaName: "value",
		},
		{
			Name:       "InitialSaleDate",
			SchemaName: "initial_sale_date",
		},
		{
			Name:       "InitialSaleStars",
			SchemaName: "initial_sale_stars",
		},
		{
			Name:       "InitialSalePrice",
			SchemaName: "initial_sale_price",
		},
		{
			Name:       "LastSaleDate",
			SchemaName: "last_sale_date",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "LastSalePrice",
			SchemaName: "last_sale_price",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "FloorPrice",
			SchemaName: "floor_price",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "AveragePrice",
			SchemaName: "average_price",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "ListedCount",
			SchemaName: "listed_count",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "FragmentListedCount",
			SchemaName: "fragment_listed_count",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "FragmentListedURL",
			SchemaName: "fragment_listed_url",
			Null:       !.Flags.Has(5),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PaymentsUniqueStarGiftValueInfo) () {
	if !(.LastSaleOnFragment == false) {
		.Flags.Set(1)
	}
	if !(.ValueIsAverage == false) {
		.Flags.Set(6)
	}
	if !(.LastSaleDate == 0) {
		.Flags.Set(0)
	}
	if !(.LastSalePrice == 0) {
		.Flags.Set(0)
	}
	if !(.FloorPrice == 0) {
		.Flags.Set(2)
	}
	if !(.AveragePrice == 0) {
		.Flags.Set(3)
	}
	if !(.ListedCount == 0) {
		.Flags.Set(4)
	}
	if !(.FragmentListedCount == 0) {
		.Flags.Set(5)
	}
	if !(.FragmentListedURL == "") {
		.Flags.Set(5)
	}
}

// Encode implements bin.Encoder.
func ( *PaymentsUniqueStarGiftValueInfo) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.uniqueStarGiftValueInfo#512fe446 as nil")
	}
	.PutID(PaymentsUniqueStarGiftValueInfoTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PaymentsUniqueStarGiftValueInfo) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.uniqueStarGiftValueInfo#512fe446 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.uniqueStarGiftValueInfo#512fe446: field flags: %w", )
	}
	.PutString(.Currency)
	.PutLong(.Value)
	.PutInt(.InitialSaleDate)
	.PutLong(.InitialSaleStars)
	.PutLong(.InitialSalePrice)
	if .Flags.Has(0) {
		.PutInt(.LastSaleDate)
	}
	if .Flags.Has(0) {
		.PutLong(.LastSalePrice)
	}
	if .Flags.Has(2) {
		.PutLong(.FloorPrice)
	}
	if .Flags.Has(3) {
		.PutLong(.AveragePrice)
	}
	if .Flags.Has(4) {
		.PutInt(.ListedCount)
	}
	if .Flags.Has(5) {
		.PutInt(.FragmentListedCount)
	}
	if .Flags.Has(5) {
		.PutString(.FragmentListedURL)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *PaymentsUniqueStarGiftValueInfo) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.uniqueStarGiftValueInfo#512fe446 to nil")
	}
	if  := .ConsumeID(PaymentsUniqueStarGiftValueInfoTypeID);  != nil {
		return fmt.Errorf("unable to decode payments.uniqueStarGiftValueInfo#512fe446: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *PaymentsUniqueStarGiftValueInfo) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.uniqueStarGiftValueInfo#512fe446 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.uniqueStarGiftValueInfo#512fe446: field flags: %w", )
		}
	}
	.LastSaleOnFragment = .Flags.Has(1)
	.ValueIsAverage = .Flags.Has(6)
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode payments.uniqueStarGiftValueInfo#512fe446: field currency: %w", )
		}
		.Currency = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.uniqueStarGiftValueInfo#512fe446: field value: %w", )
		}
		.Value = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode payments.uniqueStarGiftValueInfo#512fe446: field initial_sale_date: %w", )
		}
		.InitialSaleDate = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.uniqueStarGiftValueInfo#512fe446: field initial_sale_stars: %w", )
		}
		.InitialSaleStars = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.uniqueStarGiftValueInfo#512fe446: field initial_sale_price: %w", )
		}
		.InitialSalePrice = 
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode payments.uniqueStarGiftValueInfo#512fe446: field last_sale_date: %w", )
		}
		.LastSaleDate = 
	}
	if .Flags.Has(0) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.uniqueStarGiftValueInfo#512fe446: field last_sale_price: %w", )
		}
		.LastSalePrice = 
	}
	if .Flags.Has(2) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.uniqueStarGiftValueInfo#512fe446: field floor_price: %w", )
		}
		.FloorPrice = 
	}
	if .Flags.Has(3) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.uniqueStarGiftValueInfo#512fe446: field average_price: %w", )
		}
		.AveragePrice = 
	}
	if .Flags.Has(4) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode payments.uniqueStarGiftValueInfo#512fe446: field listed_count: %w", )
		}
		.ListedCount = 
	}
	if .Flags.Has(5) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode payments.uniqueStarGiftValueInfo#512fe446: field fragment_listed_count: %w", )
		}
		.FragmentListedCount = 
	}
	if .Flags.Has(5) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode payments.uniqueStarGiftValueInfo#512fe446: field fragment_listed_url: %w", )
		}
		.FragmentListedURL = 
	}
	return nil
}

// SetLastSaleOnFragment sets value of LastSaleOnFragment conditional field.
func ( *PaymentsUniqueStarGiftValueInfo) ( bool) {
	if  {
		.Flags.Set(1)
		.LastSaleOnFragment = true
	} else {
		.Flags.Unset(1)
		.LastSaleOnFragment = false
	}
}

// GetLastSaleOnFragment returns value of LastSaleOnFragment conditional field.
func ( *PaymentsUniqueStarGiftValueInfo) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetValueIsAverage sets value of ValueIsAverage conditional field.
func ( *PaymentsUniqueStarGiftValueInfo) ( bool) {
	if  {
		.Flags.Set(6)
		.ValueIsAverage = true
	} else {
		.Flags.Unset(6)
		.ValueIsAverage = false
	}
}

// GetValueIsAverage returns value of ValueIsAverage conditional field.
func ( *PaymentsUniqueStarGiftValueInfo) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(6)
}

// GetCurrency returns value of Currency field.
func ( *PaymentsUniqueStarGiftValueInfo) () ( string) {
	if  == nil {
		return
	}
	return .Currency
}

// GetValue returns value of Value field.
func ( *PaymentsUniqueStarGiftValueInfo) () ( int64) {
	if  == nil {
		return
	}
	return .Value
}

// GetInitialSaleDate returns value of InitialSaleDate field.
func ( *PaymentsUniqueStarGiftValueInfo) () ( int) {
	if  == nil {
		return
	}
	return .InitialSaleDate
}

// GetInitialSaleStars returns value of InitialSaleStars field.
func ( *PaymentsUniqueStarGiftValueInfo) () ( int64) {
	if  == nil {
		return
	}
	return .InitialSaleStars
}

// GetInitialSalePrice returns value of InitialSalePrice field.
func ( *PaymentsUniqueStarGiftValueInfo) () ( int64) {
	if  == nil {
		return
	}
	return .InitialSalePrice
}

// SetLastSaleDate sets value of LastSaleDate conditional field.
func ( *PaymentsUniqueStarGiftValueInfo) ( int) {
	.Flags.Set(0)
	.LastSaleDate = 
}

// GetLastSaleDate returns value of LastSaleDate conditional field and
// boolean which is true if field was set.
func ( *PaymentsUniqueStarGiftValueInfo) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .LastSaleDate, true
}

// SetLastSalePrice sets value of LastSalePrice conditional field.
func ( *PaymentsUniqueStarGiftValueInfo) ( int64) {
	.Flags.Set(0)
	.LastSalePrice = 
}

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

// SetFloorPrice sets value of FloorPrice conditional field.
func ( *PaymentsUniqueStarGiftValueInfo) ( int64) {
	.Flags.Set(2)
	.FloorPrice = 
}

// GetFloorPrice returns value of FloorPrice conditional field and
// boolean which is true if field was set.
func ( *PaymentsUniqueStarGiftValueInfo) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .FloorPrice, true
}

// SetAveragePrice sets value of AveragePrice conditional field.
func ( *PaymentsUniqueStarGiftValueInfo) ( int64) {
	.Flags.Set(3)
	.AveragePrice = 
}

// GetAveragePrice returns value of AveragePrice conditional field and
// boolean which is true if field was set.
func ( *PaymentsUniqueStarGiftValueInfo) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .AveragePrice, true
}

// SetListedCount sets value of ListedCount conditional field.
func ( *PaymentsUniqueStarGiftValueInfo) ( int) {
	.Flags.Set(4)
	.ListedCount = 
}

// GetListedCount returns value of ListedCount conditional field and
// boolean which is true if field was set.
func ( *PaymentsUniqueStarGiftValueInfo) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .ListedCount, true
}

// SetFragmentListedCount sets value of FragmentListedCount conditional field.
func ( *PaymentsUniqueStarGiftValueInfo) ( int) {
	.Flags.Set(5)
	.FragmentListedCount = 
}

// GetFragmentListedCount returns value of FragmentListedCount conditional field and
// boolean which is true if field was set.
func ( *PaymentsUniqueStarGiftValueInfo) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(5) {
		return , false
	}
	return .FragmentListedCount, true
}

// SetFragmentListedURL sets value of FragmentListedURL conditional field.
func ( *PaymentsUniqueStarGiftValueInfo) ( string) {
	.Flags.Set(5)
	.FragmentListedURL = 
}

// GetFragmentListedURL returns value of FragmentListedURL conditional field and
// boolean which is true if field was set.
func ( *PaymentsUniqueStarGiftValueInfo) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(5) {
		return , false
	}
	return .FragmentListedURL, true
}