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

// StarsGiveawayOption represents TL type `starsGiveawayOption#94ce852a`.
// Contains info about a Telegram Star giveaway¹ option.
//
// Links:
//  1. https://core.telegram.org/api/giveaways#star-giveaways
//
// See https://core.telegram.org/constructor/starsGiveawayOption for reference.
type StarsGiveawayOption struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If set, this option must only be shown in the full list of giveaway options (i.e. they
	// must be added to the list only when the user clicks on the expand button).
	Extended bool
	// If set, this option must be pre-selected by default in the option list.
	Default bool
	// The number of Telegram Stars that will be distributed among winners
	Stars int64
	// Number of times the chat will be boosted for one year if the
	// inputStorePaymentStarsGiveaway¹.boost_peer flag is populated
	//
	// Links:
	//  1) https://core.telegram.org/constructor/inputStorePaymentStarsGiveaway
	YearlyBoosts int
	// Identifier of the store product associated with the option, official apps only.
	//
	// Use SetStoreProduct and GetStoreProduct helpers.
	StoreProduct string
	// Three-letter ISO 4217 currency¹ code
	//
	// Links:
	//  1) https://core.telegram.org/bots/payments#supported-currencies
	Currency string
	// Total price in the smallest units of the currency (integer, not float/double). For
	// example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in
	// currencies.json¹, it shows the number of digits past the decimal point for each
	// currency (2 for the majority of currencies).
	//
	// Links:
	//  1) https://core.telegram.org/bots/payments/currencies.json
	Amount int64
	// Allowed options for the number of giveaway winners.
	Winners []StarsGiveawayWinnersOption
}

// StarsGiveawayOptionTypeID is TL type id of StarsGiveawayOption.
const StarsGiveawayOptionTypeID = 0x94ce852a

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

func ( *StarsGiveawayOption) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Extended == false) {
		return false
	}
	if !(.Default == false) {
		return false
	}
	if !(.Stars == 0) {
		return false
	}
	if !(.YearlyBoosts == 0) {
		return false
	}
	if !(.StoreProduct == "") {
		return false
	}
	if !(.Currency == "") {
		return false
	}
	if !(.Amount == 0) {
		return false
	}
	if !(.Winners == nil) {
		return false
	}

	return true
}

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

// FillFrom fills StarsGiveawayOption from given interface.
func ( *StarsGiveawayOption) ( interface {
	() ( bool)
	() ( bool)
	() ( int64)
	() ( int)
	() ( string,  bool)
	() ( string)
	() ( int64)
	() ( []StarsGiveawayWinnersOption)
}) {
	.Extended = .()
	.Default = .()
	.Stars = .()
	.YearlyBoosts = .()
	if ,  := .();  {
		.StoreProduct = 
	}

	.Currency = .()
	.Amount = .()
	.Winners = .()
}

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

// TypeName returns name of type in TL schema.
func (*StarsGiveawayOption) () string {
	return "starsGiveawayOption"
}

// TypeInfo returns info about TL type.
func ( *StarsGiveawayOption) () tdp.Type {
	 := tdp.Type{
		Name: "starsGiveawayOption",
		ID:   StarsGiveawayOptionTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Extended",
			SchemaName: "extended",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Default",
			SchemaName: "default",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Stars",
			SchemaName: "stars",
		},
		{
			Name:       "YearlyBoosts",
			SchemaName: "yearly_boosts",
		},
		{
			Name:       "StoreProduct",
			SchemaName: "store_product",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Currency",
			SchemaName: "currency",
		},
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
		{
			Name:       "Winners",
			SchemaName: "winners",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *StarsGiveawayOption) () {
	if !(.Extended == false) {
		.Flags.Set(0)
	}
	if !(.Default == false) {
		.Flags.Set(1)
	}
	if !(.StoreProduct == "") {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *StarsGiveawayOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starsGiveawayOption#94ce852a as nil")
	}
	.PutID(StarsGiveawayOptionTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StarsGiveawayOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starsGiveawayOption#94ce852a as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode starsGiveawayOption#94ce852a: field flags: %w", )
	}
	.PutLong(.Stars)
	.PutInt(.YearlyBoosts)
	if .Flags.Has(2) {
		.PutString(.StoreProduct)
	}
	.PutString(.Currency)
	.PutLong(.Amount)
	.PutVectorHeader(len(.Winners))
	for ,  := range .Winners {
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode starsGiveawayOption#94ce852a: field winners element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *StarsGiveawayOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starsGiveawayOption#94ce852a to nil")
	}
	if  := .ConsumeID(StarsGiveawayOptionTypeID);  != nil {
		return fmt.Errorf("unable to decode starsGiveawayOption#94ce852a: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *StarsGiveawayOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starsGiveawayOption#94ce852a to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode starsGiveawayOption#94ce852a: field flags: %w", )
		}
	}
	.Extended = .Flags.Has(0)
	.Default = .Flags.Has(1)
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode starsGiveawayOption#94ce852a: field stars: %w", )
		}
		.Stars = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starsGiveawayOption#94ce852a: field yearly_boosts: %w", )
		}
		.YearlyBoosts = 
	}
	if .Flags.Has(2) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode starsGiveawayOption#94ce852a: field store_product: %w", )
		}
		.StoreProduct = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode starsGiveawayOption#94ce852a: field currency: %w", )
		}
		.Currency = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode starsGiveawayOption#94ce852a: field amount: %w", )
		}
		.Amount = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode starsGiveawayOption#94ce852a: field winners: %w", )
		}

		if  > 0 {
			.Winners = make([]StarsGiveawayWinnersOption, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  StarsGiveawayWinnersOption
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode starsGiveawayOption#94ce852a: field winners: %w", )
			}
			.Winners = append(.Winners, )
		}
	}
	return nil
}

// SetExtended sets value of Extended conditional field.
func ( *StarsGiveawayOption) ( bool) {
	if  {
		.Flags.Set(0)
		.Extended = true
	} else {
		.Flags.Unset(0)
		.Extended = false
	}
}

// GetExtended returns value of Extended conditional field.
func ( *StarsGiveawayOption) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetDefault sets value of Default conditional field.
func ( *StarsGiveawayOption) ( bool) {
	if  {
		.Flags.Set(1)
		.Default = true
	} else {
		.Flags.Unset(1)
		.Default = false
	}
}

// GetDefault returns value of Default conditional field.
func ( *StarsGiveawayOption) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// GetStars returns value of Stars field.
func ( *StarsGiveawayOption) () ( int64) {
	if  == nil {
		return
	}
	return .Stars
}

// GetYearlyBoosts returns value of YearlyBoosts field.
func ( *StarsGiveawayOption) () ( int) {
	if  == nil {
		return
	}
	return .YearlyBoosts
}

// SetStoreProduct sets value of StoreProduct conditional field.
func ( *StarsGiveawayOption) ( string) {
	.Flags.Set(2)
	.StoreProduct = 
}

// GetStoreProduct returns value of StoreProduct conditional field and
// boolean which is true if field was set.
func ( *StarsGiveawayOption) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .StoreProduct, true
}

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

// GetAmount returns value of Amount field.
func ( *StarsGiveawayOption) () ( int64) {
	if  == nil {
		return
	}
	return .Amount
}

// GetWinners returns value of Winners field.
func ( *StarsGiveawayOption) () ( []StarsGiveawayWinnersOption) {
	if  == nil {
		return
	}
	return .Winners
}