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

// PaymentsGetStarsRevenueWithdrawalURLRequest represents TL type `payments.getStarsRevenueWithdrawalUrl#2433dc92`.
// Withdraw funds from a channel or bot's star balance »¹.
//
// Links:
//  1. https://core.telegram.org/api/stars#withdrawing-revenue
//
// See https://core.telegram.org/method/payments.getStarsRevenueWithdrawalUrl for reference.
type PaymentsGetStarsRevenueWithdrawalURLRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If set, withdraws channel/ad revenue in TON.
	Ton bool
	// Channel or bot from which to withdraw funds.
	Peer InputPeerClass
	// The amount of stars or nanotons to withdraw.
	//
	// Use SetAmount and GetAmount helpers.
	Amount int64
	// 2FA password, see here »¹ for more info.
	//
	// Links:
	//  1) https://core.telegram.org/api/srp#using-the-2fa-password
	Password InputCheckPasswordSRPClass
}

// PaymentsGetStarsRevenueWithdrawalURLRequestTypeID is TL type id of PaymentsGetStarsRevenueWithdrawalURLRequest.
const PaymentsGetStarsRevenueWithdrawalURLRequestTypeID = 0x2433dc92

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

func ( *PaymentsGetStarsRevenueWithdrawalURLRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Ton == false) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.Amount == 0) {
		return false
	}
	if !(.Password == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsGetStarsRevenueWithdrawalURLRequest from given interface.
func ( *PaymentsGetStarsRevenueWithdrawalURLRequest) ( interface {
	() ( bool)
	() ( InputPeerClass)
	() ( int64,  bool)
	() ( InputCheckPasswordSRPClass)
}) {
	.Ton = .()
	.Peer = .()
	if ,  := .();  {
		.Amount = 
	}

	.Password = .()
}

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

// TypeName returns name of type in TL schema.
func (*PaymentsGetStarsRevenueWithdrawalURLRequest) () string {
	return "payments.getStarsRevenueWithdrawalUrl"
}

// TypeInfo returns info about TL type.
func ( *PaymentsGetStarsRevenueWithdrawalURLRequest) () tdp.Type {
	 := tdp.Type{
		Name: "payments.getStarsRevenueWithdrawalUrl",
		ID:   PaymentsGetStarsRevenueWithdrawalURLRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Ton",
			SchemaName: "ton",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "Amount",
			SchemaName: "amount",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Password",
			SchemaName: "password",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *PaymentsGetStarsRevenueWithdrawalURLRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.getStarsRevenueWithdrawalUrl#2433dc92 as nil")
	}
	.PutID(PaymentsGetStarsRevenueWithdrawalURLRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PaymentsGetStarsRevenueWithdrawalURLRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.getStarsRevenueWithdrawalUrl#2433dc92 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.getStarsRevenueWithdrawalUrl#2433dc92: field flags: %w", )
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode payments.getStarsRevenueWithdrawalUrl#2433dc92: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.getStarsRevenueWithdrawalUrl#2433dc92: field peer: %w", )
	}
	if .Flags.Has(1) {
		.PutLong(.Amount)
	}
	if .Password == nil {
		return fmt.Errorf("unable to encode payments.getStarsRevenueWithdrawalUrl#2433dc92: field password is nil")
	}
	if  := .Password.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.getStarsRevenueWithdrawalUrl#2433dc92: field password: %w", )
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *PaymentsGetStarsRevenueWithdrawalURLRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.getStarsRevenueWithdrawalUrl#2433dc92 to nil")
	}
	if  := .ConsumeID(PaymentsGetStarsRevenueWithdrawalURLRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode payments.getStarsRevenueWithdrawalUrl#2433dc92: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *PaymentsGetStarsRevenueWithdrawalURLRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.getStarsRevenueWithdrawalUrl#2433dc92 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.getStarsRevenueWithdrawalUrl#2433dc92: field flags: %w", )
		}
	}
	.Ton = .Flags.Has(0)
	{
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode payments.getStarsRevenueWithdrawalUrl#2433dc92: field peer: %w", )
		}
		.Peer = 
	}
	if .Flags.Has(1) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.getStarsRevenueWithdrawalUrl#2433dc92: field amount: %w", )
		}
		.Amount = 
	}
	{
		,  := DecodeInputCheckPasswordSRP()
		if  != nil {
			return fmt.Errorf("unable to decode payments.getStarsRevenueWithdrawalUrl#2433dc92: field password: %w", )
		}
		.Password = 
	}
	return nil
}

// SetTon sets value of Ton conditional field.
func ( *PaymentsGetStarsRevenueWithdrawalURLRequest) ( bool) {
	if  {
		.Flags.Set(0)
		.Ton = true
	} else {
		.Flags.Unset(0)
		.Ton = false
	}
}

// GetTon returns value of Ton conditional field.
func ( *PaymentsGetStarsRevenueWithdrawalURLRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// GetPeer returns value of Peer field.
func ( *PaymentsGetStarsRevenueWithdrawalURLRequest) () ( InputPeerClass) {
	if  == nil {
		return
	}
	return .Peer
}

// SetAmount sets value of Amount conditional field.
func ( *PaymentsGetStarsRevenueWithdrawalURLRequest) ( int64) {
	.Flags.Set(1)
	.Amount = 
}

// GetAmount returns value of Amount conditional field and
// boolean which is true if field was set.
func ( *PaymentsGetStarsRevenueWithdrawalURLRequest) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Amount, true
}

// GetPassword returns value of Password field.
func ( *PaymentsGetStarsRevenueWithdrawalURLRequest) () ( InputCheckPasswordSRPClass) {
	if  == nil {
		return
	}
	return .Password
}

// GetPasswordAsNotEmpty returns mapped value of Password field.
func ( *PaymentsGetStarsRevenueWithdrawalURLRequest) () (*InputCheckPasswordSRP, bool) {
	return .Password.AsNotEmpty()
}

// PaymentsGetStarsRevenueWithdrawalURL invokes method payments.getStarsRevenueWithdrawalUrl#2433dc92 returning error if any.
// Withdraw funds from a channel or bot's star balance »¹.
//
// Links:
//  1. https://core.telegram.org/api/stars#withdrawing-revenue
//
// Possible errors:
//
//	400 PASSWORD_HASH_INVALID: The provided password hash is invalid.
//	400 PASSWORD_MISSING: You must enable 2FA before executing this operation.
//	400 PASSWORD_TOO_FRESH_%d: The password was modified less than 24 hours ago, try again in %d seconds.
//	400 SESSION_TOO_FRESH_%d: This session was created less than 24 hours ago, try again in %d seconds.
//
// See https://core.telegram.org/method/payments.getStarsRevenueWithdrawalUrl for reference.
func ( *Client) ( context.Context,  *PaymentsGetStarsRevenueWithdrawalURLRequest) (*PaymentsStarsRevenueWithdrawalURL, error) {
	var  PaymentsStarsRevenueWithdrawalURL

	if  := .rpc.Invoke(, , &);  != nil {
		return nil, 
	}
	return &, nil
}