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

// PremiumSubscriptionOption represents TL type `premiumSubscriptionOption#5f2d1df2`.
// Describes a Telegram Premium subscription option
//
// See https://core.telegram.org/constructor/premiumSubscriptionOption for reference.
type PremiumSubscriptionOption struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether this subscription option is currently in use.
	Current bool
	// Whether this subscription option can be used to upgrade the existing Telegram Premium
	// subscription. When upgrading Telegram Premium subscriptions bought through stores,
	// make sure that the store transaction ID is equal to transaction, to avoid upgrading
	// someone else's account, if the client is currently logged into multiple accounts.
	CanPurchaseUpgrade bool
	// Identifier of the last in-store transaction for the currently used subscription on the
	// current account.
	//
	// Use SetTransaction and GetTransaction helpers.
	Transaction string
	// Duration of subscription in months
	Months 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
	// Deep link¹ used to initiate payment
	//
	// Links:
	//  1) https://core.telegram.org/api/links
	BotURL string
	// Store product ID, only for official apps
	//
	// Use SetStoreProduct and GetStoreProduct helpers.
	StoreProduct string
}

// PremiumSubscriptionOptionTypeID is TL type id of PremiumSubscriptionOption.
const PremiumSubscriptionOptionTypeID = 0x5f2d1df2

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

func ( *PremiumSubscriptionOption) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Current == false) {
		return false
	}
	if !(.CanPurchaseUpgrade == false) {
		return false
	}
	if !(.Transaction == "") {
		return false
	}
	if !(.Months == 0) {
		return false
	}
	if !(.Currency == "") {
		return false
	}
	if !(.Amount == 0) {
		return false
	}
	if !(.BotURL == "") {
		return false
	}
	if !(.StoreProduct == "") {
		return false
	}

	return true
}

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

// FillFrom fills PremiumSubscriptionOption from given interface.
func ( *PremiumSubscriptionOption) ( interface {
	() ( bool)
	() ( bool)
	() ( string,  bool)
	() ( int)
	() ( string)
	() ( int64)
	() ( string)
	() ( string,  bool)
}) {
	.Current = .()
	.CanPurchaseUpgrade = .()
	if ,  := .();  {
		.Transaction = 
	}

	.Months = .()
	.Currency = .()
	.Amount = .()
	.BotURL = .()
	if ,  := .();  {
		.StoreProduct = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *PremiumSubscriptionOption) () tdp.Type {
	 := tdp.Type{
		Name: "premiumSubscriptionOption",
		ID:   PremiumSubscriptionOptionTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Current",
			SchemaName: "current",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "CanPurchaseUpgrade",
			SchemaName: "can_purchase_upgrade",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Transaction",
			SchemaName: "transaction",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Months",
			SchemaName: "months",
		},
		{
			Name:       "Currency",
			SchemaName: "currency",
		},
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
		{
			Name:       "BotURL",
			SchemaName: "bot_url",
		},
		{
			Name:       "StoreProduct",
			SchemaName: "store_product",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PremiumSubscriptionOption) () {
	if !(.Current == false) {
		.Flags.Set(1)
	}
	if !(.CanPurchaseUpgrade == false) {
		.Flags.Set(2)
	}
	if !(.Transaction == "") {
		.Flags.Set(3)
	}
	if !(.StoreProduct == "") {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *PremiumSubscriptionOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode premiumSubscriptionOption#5f2d1df2 as nil")
	}
	.PutID(PremiumSubscriptionOptionTypeID)
	return .EncodeBare()
}

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

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

// DecodeBare implements bin.BareDecoder.
func ( *PremiumSubscriptionOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode premiumSubscriptionOption#5f2d1df2 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode premiumSubscriptionOption#5f2d1df2: field flags: %w", )
		}
	}
	.Current = .Flags.Has(1)
	.CanPurchaseUpgrade = .Flags.Has(2)
	if .Flags.Has(3) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode premiumSubscriptionOption#5f2d1df2: field transaction: %w", )
		}
		.Transaction = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode premiumSubscriptionOption#5f2d1df2: field months: %w", )
		}
		.Months = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode premiumSubscriptionOption#5f2d1df2: field currency: %w", )
		}
		.Currency = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode premiumSubscriptionOption#5f2d1df2: field amount: %w", )
		}
		.Amount = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode premiumSubscriptionOption#5f2d1df2: field bot_url: %w", )
		}
		.BotURL = 
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode premiumSubscriptionOption#5f2d1df2: field store_product: %w", )
		}
		.StoreProduct = 
	}
	return nil
}

// SetCurrent sets value of Current conditional field.
func ( *PremiumSubscriptionOption) ( bool) {
	if  {
		.Flags.Set(1)
		.Current = true
	} else {
		.Flags.Unset(1)
		.Current = false
	}
}

// GetCurrent returns value of Current conditional field.
func ( *PremiumSubscriptionOption) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetCanPurchaseUpgrade sets value of CanPurchaseUpgrade conditional field.
func ( *PremiumSubscriptionOption) ( bool) {
	if  {
		.Flags.Set(2)
		.CanPurchaseUpgrade = true
	} else {
		.Flags.Unset(2)
		.CanPurchaseUpgrade = false
	}
}

// GetCanPurchaseUpgrade returns value of CanPurchaseUpgrade conditional field.
func ( *PremiumSubscriptionOption) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetTransaction sets value of Transaction conditional field.
func ( *PremiumSubscriptionOption) ( string) {
	.Flags.Set(3)
	.Transaction = 
}

// GetTransaction returns value of Transaction conditional field and
// boolean which is true if field was set.
func ( *PremiumSubscriptionOption) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .Transaction, true
}

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

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

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

// GetBotURL returns value of BotURL field.
func ( *PremiumSubscriptionOption) () ( string) {
	if  == nil {
		return
	}
	return .BotURL
}

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

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