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

// StarsGiftOption represents TL type `starsGiftOption#5e0589f1`.
// Telegram Stars gift option¹.
//
// Links:
//  1. https://core.telegram.org/api/stars#buying-or-gifting-stars
//
// See https://core.telegram.org/constructor/starsGiftOption for reference.
type StarsGiftOption struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If set, the option must only be shown in the full list of topup options.
	Extended bool
	// Amount of Telegram stars.
	Stars int64
	// 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
	// Price of the product 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
}

// StarsGiftOptionTypeID is TL type id of StarsGiftOption.
const StarsGiftOptionTypeID = 0x5e0589f1

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

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

	return true
}

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

// FillFrom fills StarsGiftOption from given interface.
func ( *StarsGiftOption) ( interface {
	() ( bool)
	() ( int64)
	() ( string,  bool)
	() ( string)
	() ( int64)
}) {
	.Extended = .()
	.Stars = .()
	if ,  := .();  {
		.StoreProduct = 
	}

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

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

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

// TypeInfo returns info about TL type.
func ( *StarsGiftOption) () tdp.Type {
	 := tdp.Type{
		Name: "starsGiftOption",
		ID:   StarsGiftOptionTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Extended",
			SchemaName: "extended",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Stars",
			SchemaName: "stars",
		},
		{
			Name:       "StoreProduct",
			SchemaName: "store_product",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Currency",
			SchemaName: "currency",
		},
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *StarsGiftOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starsGiftOption#5e0589f1 as nil")
	}
	.PutID(StarsGiftOptionTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StarsGiftOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starsGiftOption#5e0589f1 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode starsGiftOption#5e0589f1: field flags: %w", )
	}
	.PutLong(.Stars)
	if .Flags.Has(0) {
		.PutString(.StoreProduct)
	}
	.PutString(.Currency)
	.PutLong(.Amount)
	return nil
}

// Decode implements bin.Decoder.
func ( *StarsGiftOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starsGiftOption#5e0589f1 to nil")
	}
	if  := .ConsumeID(StarsGiftOptionTypeID);  != nil {
		return fmt.Errorf("unable to decode starsGiftOption#5e0589f1: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *StarsGiftOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starsGiftOption#5e0589f1 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode starsGiftOption#5e0589f1: field flags: %w", )
		}
	}
	.Extended = .Flags.Has(1)
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode starsGiftOption#5e0589f1: field stars: %w", )
		}
		.Stars = 
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode starsGiftOption#5e0589f1: field store_product: %w", )
		}
		.StoreProduct = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode starsGiftOption#5e0589f1: field currency: %w", )
		}
		.Currency = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode starsGiftOption#5e0589f1: field amount: %w", )
		}
		.Amount = 
	}
	return nil
}

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

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

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

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

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

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

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