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

// PaymentsUpgradeStarGiftRequest represents TL type `payments.upgradeStarGift#aed6e4f5`.
// Upgrade a gift¹ to a collectible gift²: can only be used if the upgrade was already
// paid by the gift sender; see here »³ for more info on the full flow (including the
// different flow to use in case the upgrade was not paid by the gift sender).
//
// Links:
//  1. https://core.telegram.org/api/gifts
//  2. https://core.telegram.org/api/gifts#collectible-gifts
//  3. https://core.telegram.org/api/gifts#upgrade-a-gift-to-a-collectible-gift
//
// See https://core.telegram.org/method/payments.upgradeStarGift for reference.
type PaymentsUpgradeStarGiftRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Set this flag to keep the original gift text, sender and receiver in the upgraded gift
	// as a starGiftAttributeOriginalDetails¹ attribute.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/starGiftAttributeOriginalDetails
	KeepOriginalDetails bool
	// The gift to upgrade
	Stargift InputSavedStarGiftClass
}

// PaymentsUpgradeStarGiftRequestTypeID is TL type id of PaymentsUpgradeStarGiftRequest.
const PaymentsUpgradeStarGiftRequestTypeID = 0xaed6e4f5

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

func ( *PaymentsUpgradeStarGiftRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.KeepOriginalDetails == false) {
		return false
	}
	if !(.Stargift == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsUpgradeStarGiftRequest from given interface.
func ( *PaymentsUpgradeStarGiftRequest) ( interface {
	() ( bool)
	() ( InputSavedStarGiftClass)
}) {
	.KeepOriginalDetails = .()
	.Stargift = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PaymentsUpgradeStarGiftRequest) () tdp.Type {
	 := tdp.Type{
		Name: "payments.upgradeStarGift",
		ID:   PaymentsUpgradeStarGiftRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "KeepOriginalDetails",
			SchemaName: "keep_original_details",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Stargift",
			SchemaName: "stargift",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *PaymentsUpgradeStarGiftRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.upgradeStarGift#aed6e4f5 as nil")
	}
	.PutID(PaymentsUpgradeStarGiftRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PaymentsUpgradeStarGiftRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.upgradeStarGift#aed6e4f5 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.upgradeStarGift#aed6e4f5: field flags: %w", )
	}
	if .Stargift == nil {
		return fmt.Errorf("unable to encode payments.upgradeStarGift#aed6e4f5: field stargift is nil")
	}
	if  := .Stargift.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.upgradeStarGift#aed6e4f5: field stargift: %w", )
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PaymentsUpgradeStarGiftRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.upgradeStarGift#aed6e4f5 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.upgradeStarGift#aed6e4f5: field flags: %w", )
		}
	}
	.KeepOriginalDetails = .Flags.Has(0)
	{
		,  := DecodeInputSavedStarGift()
		if  != nil {
			return fmt.Errorf("unable to decode payments.upgradeStarGift#aed6e4f5: field stargift: %w", )
		}
		.Stargift = 
	}
	return nil
}

// SetKeepOriginalDetails sets value of KeepOriginalDetails conditional field.
func ( *PaymentsUpgradeStarGiftRequest) ( bool) {
	if  {
		.Flags.Set(0)
		.KeepOriginalDetails = true
	} else {
		.Flags.Unset(0)
		.KeepOriginalDetails = false
	}
}

// GetKeepOriginalDetails returns value of KeepOriginalDetails conditional field.
func ( *PaymentsUpgradeStarGiftRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// GetStargift returns value of Stargift field.
func ( *PaymentsUpgradeStarGiftRequest) () ( InputSavedStarGiftClass) {
	if  == nil {
		return
	}
	return .Stargift
}

// PaymentsUpgradeStarGift invokes method payments.upgradeStarGift#aed6e4f5 returning error if any.
// Upgrade a gift¹ to a collectible gift²: can only be used if the upgrade was already
// paid by the gift sender; see here »³ for more info on the full flow (including the
// different flow to use in case the upgrade was not paid by the gift sender).
//
// Links:
//  1. https://core.telegram.org/api/gifts
//  2. https://core.telegram.org/api/gifts#collectible-gifts
//  3. https://core.telegram.org/api/gifts#upgrade-a-gift-to-a-collectible-gift
//
// Possible errors:
//
//	400 BUSINESS_CONNECTION_INVALID: The connection_id passed to the wrapping invokeWithBusinessConnection call is invalid.
//	400 MESSAGE_ID_INVALID: The provided message id is invalid.
//	400 PAYMENT_REQUIRED: Payment is required for this action, see here » for more info.
//	400 SAVED_ID_EMPTY: The passed inputSavedStarGiftChat.saved_id is empty.
//	400 STARGIFT_ALREADY_CONVERTED: The specified star gift was already converted to Stars.
//	400 STARGIFT_ALREADY_UPGRADED: The specified gift was already upgraded to a collectible gift.
//	400 STARGIFT_UPGRADE_UNAVAILABLE: A received gift can only be upgraded to a collectible gift if the messageActionStarGift/savedStarGift.can_upgrade flag is set.
//
// See https://core.telegram.org/method/payments.upgradeStarGift for reference.
func ( *Client) ( context.Context,  *PaymentsUpgradeStarGiftRequest) (UpdatesClass, error) {
	var  UpdatesBox

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