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

// PaymentsBotCancelStarsSubscriptionRequest represents TL type `payments.botCancelStarsSubscription#6dfa0622`.
// Cancel a bot subscription¹
//
// Links:
//  1. https://core.telegram.org/api/subscriptions#bot-subscriptions
//
// See https://core.telegram.org/method/payments.botCancelStarsSubscription for reference.
type PaymentsBotCancelStarsSubscriptionRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If not set, disables autorenewal of the subscriptions, and prevents the user from
	// reactivating the subscription once the current period expires: a subscription
	// cancelled by the bot will have the starsSubscription¹.bot_canceled flag set.  The bot
	// can can partially undo this operation by setting this flag: this will allow the user
	// to reactivate the subscription.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/starsSubscription
	Restore bool
	// The ID of the user whose subscription should be (un)cancelled
	UserID InputUserClass
	// The provider_charge_id from the messageActionPaymentSentMe¹ service message sent to
	// the bot for the first subscription payment.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/messageActionPaymentSentMe
	ChargeID string
}

// PaymentsBotCancelStarsSubscriptionRequestTypeID is TL type id of PaymentsBotCancelStarsSubscriptionRequest.
const PaymentsBotCancelStarsSubscriptionRequestTypeID = 0x6dfa0622

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

func ( *PaymentsBotCancelStarsSubscriptionRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Restore == false) {
		return false
	}
	if !(.UserID == nil) {
		return false
	}
	if !(.ChargeID == "") {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsBotCancelStarsSubscriptionRequest from given interface.
func ( *PaymentsBotCancelStarsSubscriptionRequest) ( interface {
	() ( bool)
	() ( InputUserClass)
	() ( string)
}) {
	.Restore = .()
	.UserID = .()
	.ChargeID = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PaymentsBotCancelStarsSubscriptionRequest) () tdp.Type {
	 := tdp.Type{
		Name: "payments.botCancelStarsSubscription",
		ID:   PaymentsBotCancelStarsSubscriptionRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Restore",
			SchemaName: "restore",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
		{
			Name:       "ChargeID",
			SchemaName: "charge_id",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PaymentsBotCancelStarsSubscriptionRequest) () {
	if !(.Restore == false) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *PaymentsBotCancelStarsSubscriptionRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.botCancelStarsSubscription#6dfa0622 as nil")
	}
	.PutID(PaymentsBotCancelStarsSubscriptionRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PaymentsBotCancelStarsSubscriptionRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.botCancelStarsSubscription#6dfa0622 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.botCancelStarsSubscription#6dfa0622: field flags: %w", )
	}
	if .UserID == nil {
		return fmt.Errorf("unable to encode payments.botCancelStarsSubscription#6dfa0622: field user_id is nil")
	}
	if  := .UserID.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.botCancelStarsSubscription#6dfa0622: field user_id: %w", )
	}
	.PutString(.ChargeID)
	return nil
}

// Decode implements bin.Decoder.
func ( *PaymentsBotCancelStarsSubscriptionRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.botCancelStarsSubscription#6dfa0622 to nil")
	}
	if  := .ConsumeID(PaymentsBotCancelStarsSubscriptionRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode payments.botCancelStarsSubscription#6dfa0622: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *PaymentsBotCancelStarsSubscriptionRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.botCancelStarsSubscription#6dfa0622 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.botCancelStarsSubscription#6dfa0622: field flags: %w", )
		}
	}
	.Restore = .Flags.Has(0)
	{
		,  := DecodeInputUser()
		if  != nil {
			return fmt.Errorf("unable to decode payments.botCancelStarsSubscription#6dfa0622: field user_id: %w", )
		}
		.UserID = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode payments.botCancelStarsSubscription#6dfa0622: field charge_id: %w", )
		}
		.ChargeID = 
	}
	return nil
}

// SetRestore sets value of Restore conditional field.
func ( *PaymentsBotCancelStarsSubscriptionRequest) ( bool) {
	if  {
		.Flags.Set(0)
		.Restore = true
	} else {
		.Flags.Unset(0)
		.Restore = false
	}
}

// GetRestore returns value of Restore conditional field.
func ( *PaymentsBotCancelStarsSubscriptionRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// GetUserID returns value of UserID field.
func ( *PaymentsBotCancelStarsSubscriptionRequest) () ( InputUserClass) {
	if  == nil {
		return
	}
	return .UserID
}

// GetChargeID returns value of ChargeID field.
func ( *PaymentsBotCancelStarsSubscriptionRequest) () ( string) {
	if  == nil {
		return
	}
	return .ChargeID
}

// PaymentsBotCancelStarsSubscription invokes method payments.botCancelStarsSubscription#6dfa0622 returning error if any.
// Cancel a bot subscription¹
//
// Links:
//  1. https://core.telegram.org/api/subscriptions#bot-subscriptions
//
// Possible errors:
//
//	400 CHARGE_ID_INVALID: The specified charge_id is invalid.
//	400 USER_ID_INVALID: The provided user ID is invalid.
//
// See https://core.telegram.org/method/payments.botCancelStarsSubscription for reference.
func ( *Client) ( context.Context,  *PaymentsBotCancelStarsSubscriptionRequest) (bool, error) {
	var  BoolBox

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