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

// StarsRevenueStatus represents TL type `starsRevenueStatus#febe5491`.
// Describes Telegram Star revenue balances »¹.
//
// Links:
//  1. https://core.telegram.org/api/stars
//
// See https://core.telegram.org/constructor/starsRevenueStatus for reference.
type StarsRevenueStatus struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If set, the user may withdraw¹ up to available_balance stars.
	//
	// Links:
	//  1) https://core.telegram.org/api/stars#withdrawing-revenue
	WithdrawalEnabled bool
	// Amount of not-yet-withdrawn Telegram Stars.
	CurrentBalance StarsAmountClass
	// Amount of withdrawable Telegram Stars.
	AvailableBalance StarsAmountClass
	// Total amount of earned Telegram Stars.
	OverallRevenue StarsAmountClass
	// Unixtime indicating when will withdrawal be available to the user. If not set,
	// withdrawal can be started now.
	//
	// Use SetNextWithdrawalAt and GetNextWithdrawalAt helpers.
	NextWithdrawalAt int
}

// StarsRevenueStatusTypeID is TL type id of StarsRevenueStatus.
const StarsRevenueStatusTypeID = 0xfebe5491

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

func ( *StarsRevenueStatus) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.WithdrawalEnabled == false) {
		return false
	}
	if !(.CurrentBalance == nil) {
		return false
	}
	if !(.AvailableBalance == nil) {
		return false
	}
	if !(.OverallRevenue == nil) {
		return false
	}
	if !(.NextWithdrawalAt == 0) {
		return false
	}

	return true
}

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

// FillFrom fills StarsRevenueStatus from given interface.
func ( *StarsRevenueStatus) ( interface {
	() ( bool)
	() ( StarsAmountClass)
	() ( StarsAmountClass)
	() ( StarsAmountClass)
	() ( int,  bool)
}) {
	.WithdrawalEnabled = .()
	.CurrentBalance = .()
	.AvailableBalance = .()
	.OverallRevenue = .()
	if ,  := .();  {
		.NextWithdrawalAt = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *StarsRevenueStatus) () tdp.Type {
	 := tdp.Type{
		Name: "starsRevenueStatus",
		ID:   StarsRevenueStatusTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "WithdrawalEnabled",
			SchemaName: "withdrawal_enabled",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "CurrentBalance",
			SchemaName: "current_balance",
		},
		{
			Name:       "AvailableBalance",
			SchemaName: "available_balance",
		},
		{
			Name:       "OverallRevenue",
			SchemaName: "overall_revenue",
		},
		{
			Name:       "NextWithdrawalAt",
			SchemaName: "next_withdrawal_at",
			Null:       !.Flags.Has(1),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *StarsRevenueStatus) () {
	if !(.WithdrawalEnabled == false) {
		.Flags.Set(0)
	}
	if !(.NextWithdrawalAt == 0) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *StarsRevenueStatus) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starsRevenueStatus#febe5491 as nil")
	}
	.PutID(StarsRevenueStatusTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StarsRevenueStatus) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starsRevenueStatus#febe5491 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode starsRevenueStatus#febe5491: field flags: %w", )
	}
	if .CurrentBalance == nil {
		return fmt.Errorf("unable to encode starsRevenueStatus#febe5491: field current_balance is nil")
	}
	if  := .CurrentBalance.Encode();  != nil {
		return fmt.Errorf("unable to encode starsRevenueStatus#febe5491: field current_balance: %w", )
	}
	if .AvailableBalance == nil {
		return fmt.Errorf("unable to encode starsRevenueStatus#febe5491: field available_balance is nil")
	}
	if  := .AvailableBalance.Encode();  != nil {
		return fmt.Errorf("unable to encode starsRevenueStatus#febe5491: field available_balance: %w", )
	}
	if .OverallRevenue == nil {
		return fmt.Errorf("unable to encode starsRevenueStatus#febe5491: field overall_revenue is nil")
	}
	if  := .OverallRevenue.Encode();  != nil {
		return fmt.Errorf("unable to encode starsRevenueStatus#febe5491: field overall_revenue: %w", )
	}
	if .Flags.Has(1) {
		.PutInt(.NextWithdrawalAt)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *StarsRevenueStatus) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starsRevenueStatus#febe5491 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode starsRevenueStatus#febe5491: field flags: %w", )
		}
	}
	.WithdrawalEnabled = .Flags.Has(0)
	{
		,  := DecodeStarsAmount()
		if  != nil {
			return fmt.Errorf("unable to decode starsRevenueStatus#febe5491: field current_balance: %w", )
		}
		.CurrentBalance = 
	}
	{
		,  := DecodeStarsAmount()
		if  != nil {
			return fmt.Errorf("unable to decode starsRevenueStatus#febe5491: field available_balance: %w", )
		}
		.AvailableBalance = 
	}
	{
		,  := DecodeStarsAmount()
		if  != nil {
			return fmt.Errorf("unable to decode starsRevenueStatus#febe5491: field overall_revenue: %w", )
		}
		.OverallRevenue = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starsRevenueStatus#febe5491: field next_withdrawal_at: %w", )
		}
		.NextWithdrawalAt = 
	}
	return nil
}

// SetWithdrawalEnabled sets value of WithdrawalEnabled conditional field.
func ( *StarsRevenueStatus) ( bool) {
	if  {
		.Flags.Set(0)
		.WithdrawalEnabled = true
	} else {
		.Flags.Unset(0)
		.WithdrawalEnabled = false
	}
}

// GetWithdrawalEnabled returns value of WithdrawalEnabled conditional field.
func ( *StarsRevenueStatus) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// GetCurrentBalance returns value of CurrentBalance field.
func ( *StarsRevenueStatus) () ( StarsAmountClass) {
	if  == nil {
		return
	}
	return .CurrentBalance
}

// GetAvailableBalance returns value of AvailableBalance field.
func ( *StarsRevenueStatus) () ( StarsAmountClass) {
	if  == nil {
		return
	}
	return .AvailableBalance
}

// GetOverallRevenue returns value of OverallRevenue field.
func ( *StarsRevenueStatus) () ( StarsAmountClass) {
	if  == nil {
		return
	}
	return .OverallRevenue
}

// SetNextWithdrawalAt sets value of NextWithdrawalAt conditional field.
func ( *StarsRevenueStatus) ( int) {
	.Flags.Set(1)
	.NextWithdrawalAt = 
}

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