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

// PremiumGiftCodeOption represents TL type `premiumGiftCodeOption#257e962b`.
// Contains info about a giveaway/gift¹ option.
//
// Links:
//  1. https://core.telegram.org/api/giveaways
//
// See https://core.telegram.org/constructor/premiumGiftCodeOption for reference.
type PremiumGiftCodeOption struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Number of users which will be able to activate the gift codes.
	Users int
	// Duration in months of each gifted Telegram Premium¹ subscription.
	//
	// Links:
	//  1) https://core.telegram.org/api/premium
	Months int
	// Identifier of the store product associated with the option, official apps only.
	//
	// Use SetStoreProduct and GetStoreProduct helpers.
	StoreProduct string
	// Number of times the store product must be paid
	//
	// Use SetStoreQuantity and GetStoreQuantity helpers.
	StoreQuantity int
	// 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
}

// PremiumGiftCodeOptionTypeID is TL type id of PremiumGiftCodeOption.
const PremiumGiftCodeOptionTypeID = 0x257e962b

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

func ( *PremiumGiftCodeOption) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Users == 0) {
		return false
	}
	if !(.Months == 0) {
		return false
	}
	if !(.StoreProduct == "") {
		return false
	}
	if !(.StoreQuantity == 0) {
		return false
	}
	if !(.Currency == "") {
		return false
	}
	if !(.Amount == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PremiumGiftCodeOption from given interface.
func ( *PremiumGiftCodeOption) ( interface {
	() ( int)
	() ( int)
	() ( string,  bool)
	() ( int,  bool)
	() ( string)
	() ( int64)
}) {
	.Users = .()
	.Months = .()
	if ,  := .();  {
		.StoreProduct = 
	}

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

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

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

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

// TypeInfo returns info about TL type.
func ( *PremiumGiftCodeOption) () tdp.Type {
	 := tdp.Type{
		Name: "premiumGiftCodeOption",
		ID:   PremiumGiftCodeOptionTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Users",
			SchemaName: "users",
		},
		{
			Name:       "Months",
			SchemaName: "months",
		},
		{
			Name:       "StoreProduct",
			SchemaName: "store_product",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "StoreQuantity",
			SchemaName: "store_quantity",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Currency",
			SchemaName: "currency",
		},
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *PremiumGiftCodeOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode premiumGiftCodeOption#257e962b as nil")
	}
	.PutID(PremiumGiftCodeOptionTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PremiumGiftCodeOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode premiumGiftCodeOption#257e962b as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode premiumGiftCodeOption#257e962b: field flags: %w", )
	}
	.PutInt(.Users)
	.PutInt(.Months)
	if .Flags.Has(0) {
		.PutString(.StoreProduct)
	}
	if .Flags.Has(1) {
		.PutInt(.StoreQuantity)
	}
	.PutString(.Currency)
	.PutLong(.Amount)
	return nil
}

// Decode implements bin.Decoder.
func ( *PremiumGiftCodeOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode premiumGiftCodeOption#257e962b to nil")
	}
	if  := .ConsumeID(PremiumGiftCodeOptionTypeID);  != nil {
		return fmt.Errorf("unable to decode premiumGiftCodeOption#257e962b: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *PremiumGiftCodeOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode premiumGiftCodeOption#257e962b to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode premiumGiftCodeOption#257e962b: field flags: %w", )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode premiumGiftCodeOption#257e962b: field users: %w", )
		}
		.Users = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode premiumGiftCodeOption#257e962b: field months: %w", )
		}
		.Months = 
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode premiumGiftCodeOption#257e962b: field store_product: %w", )
		}
		.StoreProduct = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode premiumGiftCodeOption#257e962b: field store_quantity: %w", )
		}
		.StoreQuantity = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode premiumGiftCodeOption#257e962b: field currency: %w", )
		}
		.Currency = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode premiumGiftCodeOption#257e962b: field amount: %w", )
		}
		.Amount = 
	}
	return nil
}

// GetUsers returns value of Users field.
func ( *PremiumGiftCodeOption) () ( int) {
	if  == nil {
		return
	}
	return .Users
}

// GetMonths returns value of Months field.
func ( *PremiumGiftCodeOption) () ( int) {
	if  == nil {
		return
	}
	return .Months
}

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

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

// SetStoreQuantity sets value of StoreQuantity conditional field.
func ( *PremiumGiftCodeOption) ( int) {
	.Flags.Set(1)
	.StoreQuantity = 
}

// GetStoreQuantity returns value of StoreQuantity conditional field and
// boolean which is true if field was set.
func ( *PremiumGiftCodeOption) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .StoreQuantity, true
}

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

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