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

// StarsAmount represents TL type `starsAmount#bbb6b4a3`.
// Describes a real (i.e. possibly decimal) amount of Telegram Stars¹.
//
// Links:
//  1. https://core.telegram.org/api/stars
//
// See https://core.telegram.org/constructor/starsAmount for reference.
type StarsAmount struct {
	// The integer amount of Telegram Stars.
	Amount int64
	// The decimal amount of Telegram Stars, expressed as nanostars (i.e. 1 nanostar is equal
	// to 1/1_000_000_000th (one billionth) of a Telegram Star). This field may also be
	// negative (the allowed range is from -999_999_999 to 999_999_999).
	Nanos int
}

// StarsAmountTypeID is TL type id of StarsAmount.
const StarsAmountTypeID = 0xbbb6b4a3

// construct implements constructor of StarsAmountClass.
func ( StarsAmount) () StarsAmountClass { return & }

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

	_ StarsAmountClass = &StarsAmount{}
)

func ( *StarsAmount) () bool {
	if  == nil {
		return true
	}
	if !(.Amount == 0) {
		return false
	}
	if !(.Nanos == 0) {
		return false
	}

	return true
}

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

// FillFrom fills StarsAmount from given interface.
func ( *StarsAmount) ( interface {
	() ( int64)
	() ( int)
}) {
	.Amount = .()
	.Nanos = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *StarsAmount) () tdp.Type {
	 := tdp.Type{
		Name: "starsAmount",
		ID:   StarsAmountTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
		{
			Name:       "Nanos",
			SchemaName: "nanos",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *StarsAmount) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starsAmount#bbb6b4a3 as nil")
	}
	.PutID(StarsAmountTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StarsAmount) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starsAmount#bbb6b4a3 as nil")
	}
	.PutLong(.Amount)
	.PutInt(.Nanos)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *StarsAmount) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starsAmount#bbb6b4a3 to nil")
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode starsAmount#bbb6b4a3: field amount: %w", )
		}
		.Amount = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starsAmount#bbb6b4a3: field nanos: %w", )
		}
		.Nanos = 
	}
	return nil
}

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

// GetNanos returns value of Nanos field.
func ( *StarsAmount) () ( int) {
	if  == nil {
		return
	}
	return .Nanos
}

// StarsTonAmount represents TL type `starsTonAmount#74aee3e0`.
// Describes an amount of toncoin in nanotons (i.e. 1/1_000_000_000 of a toncoin).
//
// See https://core.telegram.org/constructor/starsTonAmount for reference.
type StarsTonAmount struct {
	// The amount in nanotons.
	Amount int64
}

// StarsTonAmountTypeID is TL type id of StarsTonAmount.
const StarsTonAmountTypeID = 0x74aee3e0

// construct implements constructor of StarsAmountClass.
func ( StarsTonAmount) () StarsAmountClass { return & }

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

	_ StarsAmountClass = &StarsTonAmount{}
)

func ( *StarsTonAmount) () bool {
	if  == nil {
		return true
	}
	if !(.Amount == 0) {
		return false
	}

	return true
}

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

// FillFrom fills StarsTonAmount from given interface.
func ( *StarsTonAmount) ( interface {
	() ( int64)
}) {
	.Amount = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *StarsTonAmount) () tdp.Type {
	 := tdp.Type{
		Name: "starsTonAmount",
		ID:   StarsTonAmountTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *StarsTonAmount) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starsTonAmount#74aee3e0 as nil")
	}
	.PutID(StarsTonAmountTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StarsTonAmount) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starsTonAmount#74aee3e0 as nil")
	}
	.PutLong(.Amount)
	return nil
}

// Decode implements bin.Decoder.
func ( *StarsTonAmount) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starsTonAmount#74aee3e0 to nil")
	}
	if  := .ConsumeID(StarsTonAmountTypeID);  != nil {
		return fmt.Errorf("unable to decode starsTonAmount#74aee3e0: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *StarsTonAmount) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starsTonAmount#74aee3e0 to nil")
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode starsTonAmount#74aee3e0: field amount: %w", )
		}
		.Amount = 
	}
	return nil
}

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

// StarsAmountClassName is schema name of StarsAmountClass.
const StarsAmountClassName = "StarsAmount"

// StarsAmountClass represents StarsAmount generic type.
//
// See https://core.telegram.org/type/StarsAmount for reference.
//
// Constructors:
//   - [StarsAmount]
//   - [StarsTonAmount]
//
// Example:
//
//	g, err := tg.DecodeStarsAmount(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.StarsAmount: // starsAmount#bbb6b4a3
//	case *tg.StarsTonAmount: // starsTonAmount#74aee3e0
//	default: panic(v)
//	}
type StarsAmountClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() StarsAmountClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	// The integer amount of Telegram Stars.
	GetAmount() (value int64)
}

// DecodeStarsAmount implements binary de-serialization for StarsAmountClass.
func ( *bin.Buffer) (StarsAmountClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case StarsAmountTypeID:
		// Decoding starsAmount#bbb6b4a3.
		 := StarsAmount{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode StarsAmountClass: %w", )
		}
		return &, nil
	case StarsTonAmountTypeID:
		// Decoding starsTonAmount#74aee3e0.
		 := StarsTonAmount{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode StarsAmountClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode StarsAmountClass: %w", bin.NewUnexpectedID())
	}
}

// StarsAmount boxes the StarsAmountClass providing a helper.
type StarsAmountBox struct {
	StarsAmount StarsAmountClass
}

// Decode implements bin.Decoder for StarsAmountBox.
func ( *StarsAmountBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode StarsAmountBox to nil")
	}
	,  := DecodeStarsAmount()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.StarsAmount = 
	return nil
}

// Encode implements bin.Encode for StarsAmountBox.
func ( *StarsAmountBox) ( *bin.Buffer) error {
	if  == nil || .StarsAmount == nil {
		return fmt.Errorf("unable to encode StarsAmountClass as nil")
	}
	return .StarsAmount.Encode()
}