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

// PaymentsSendStarGiftOfferRequest represents TL type `payments.sendStarGiftOffer#8fb86b41`.
// Send an offer to purchase a collectible gift »¹, see here »² for the full flow.
//
// Links:
//  1. https://core.telegram.org/api/gifts#collectible-gift-purchase-offers
//  2. https://core.telegram.org/api/gifts#collectible-gift-purchase-offers
//
// See https://core.telegram.org/method/payments.sendStarGiftOffer for reference.
type PaymentsSendStarGiftOfferRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Owner of the collectible gift: equal to starGiftUnique¹.owner_id.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/starGiftUnique
	Peer InputPeerClass
	// Identifier of the collectible gift: equal to starGiftUnique¹.slug.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/starGiftUnique
	Slug string
	// Offer price, in stars or TON.
	Price StarsAmountClass
	// Duration of the offer, in seconds: must be one of 21600, 43200, 86400, 129600, 172800,
	// or 259200; can also be 120 in test mode.
	Duration int
	// Random 64-bit identifier used to avoid sending the same offer twice in case of network
	// issues.
	RandomID int64
	// If the destination peer has paid messages »¹ enabled, specifies the amount of
	// Telegram Stars² the sending user has agreed to pay in order to send the offer (in
	// addition to the amount for the offer itself, contained in price).
	//
	// Links:
	//  1) https://core.telegram.org/api/paid-messages
	//  2) https://core.telegram.org/api/stars
	//
	// Use SetAllowPaidStars and GetAllowPaidStars helpers.
	AllowPaidStars int64
}

// PaymentsSendStarGiftOfferRequestTypeID is TL type id of PaymentsSendStarGiftOfferRequest.
const PaymentsSendStarGiftOfferRequestTypeID = 0x8fb86b41

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

func ( *PaymentsSendStarGiftOfferRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.Slug == "") {
		return false
	}
	if !(.Price == nil) {
		return false
	}
	if !(.Duration == 0) {
		return false
	}
	if !(.RandomID == 0) {
		return false
	}
	if !(.AllowPaidStars == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsSendStarGiftOfferRequest from given interface.
func ( *PaymentsSendStarGiftOfferRequest) ( interface {
	() ( InputPeerClass)
	() ( string)
	() ( StarsAmountClass)
	() ( int)
	() ( int64)
	() ( int64,  bool)
}) {
	.Peer = .()
	.Slug = .()
	.Price = .()
	.Duration = .()
	.RandomID = .()
	if ,  := .();  {
		.AllowPaidStars = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *PaymentsSendStarGiftOfferRequest) () tdp.Type {
	 := tdp.Type{
		Name: "payments.sendStarGiftOffer",
		ID:   PaymentsSendStarGiftOfferRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "Slug",
			SchemaName: "slug",
		},
		{
			Name:       "Price",
			SchemaName: "price",
		},
		{
			Name:       "Duration",
			SchemaName: "duration",
		},
		{
			Name:       "RandomID",
			SchemaName: "random_id",
		},
		{
			Name:       "AllowPaidStars",
			SchemaName: "allow_paid_stars",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *PaymentsSendStarGiftOfferRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.sendStarGiftOffer#8fb86b41 as nil")
	}
	.PutID(PaymentsSendStarGiftOfferRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PaymentsSendStarGiftOfferRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.sendStarGiftOffer#8fb86b41 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.sendStarGiftOffer#8fb86b41: field flags: %w", )
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode payments.sendStarGiftOffer#8fb86b41: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.sendStarGiftOffer#8fb86b41: field peer: %w", )
	}
	.PutString(.Slug)
	if .Price == nil {
		return fmt.Errorf("unable to encode payments.sendStarGiftOffer#8fb86b41: field price is nil")
	}
	if  := .Price.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.sendStarGiftOffer#8fb86b41: field price: %w", )
	}
	.PutInt(.Duration)
	.PutLong(.RandomID)
	if .Flags.Has(0) {
		.PutLong(.AllowPaidStars)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PaymentsSendStarGiftOfferRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.sendStarGiftOffer#8fb86b41 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.sendStarGiftOffer#8fb86b41: field flags: %w", )
		}
	}
	{
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode payments.sendStarGiftOffer#8fb86b41: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode payments.sendStarGiftOffer#8fb86b41: field slug: %w", )
		}
		.Slug = 
	}
	{
		,  := DecodeStarsAmount()
		if  != nil {
			return fmt.Errorf("unable to decode payments.sendStarGiftOffer#8fb86b41: field price: %w", )
		}
		.Price = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode payments.sendStarGiftOffer#8fb86b41: field duration: %w", )
		}
		.Duration = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.sendStarGiftOffer#8fb86b41: field random_id: %w", )
		}
		.RandomID = 
	}
	if .Flags.Has(0) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.sendStarGiftOffer#8fb86b41: field allow_paid_stars: %w", )
		}
		.AllowPaidStars = 
	}
	return nil
}

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

// GetSlug returns value of Slug field.
func ( *PaymentsSendStarGiftOfferRequest) () ( string) {
	if  == nil {
		return
	}
	return .Slug
}

// GetPrice returns value of Price field.
func ( *PaymentsSendStarGiftOfferRequest) () ( StarsAmountClass) {
	if  == nil {
		return
	}
	return .Price
}

// GetDuration returns value of Duration field.
func ( *PaymentsSendStarGiftOfferRequest) () ( int) {
	if  == nil {
		return
	}
	return .Duration
}

// GetRandomID returns value of RandomID field.
func ( *PaymentsSendStarGiftOfferRequest) () ( int64) {
	if  == nil {
		return
	}
	return .RandomID
}

// SetAllowPaidStars sets value of AllowPaidStars conditional field.
func ( *PaymentsSendStarGiftOfferRequest) ( int64) {
	.Flags.Set(0)
	.AllowPaidStars = 
}

// GetAllowPaidStars returns value of AllowPaidStars conditional field and
// boolean which is true if field was set.
func ( *PaymentsSendStarGiftOfferRequest) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .AllowPaidStars, true
}

// PaymentsSendStarGiftOffer invokes method payments.sendStarGiftOffer#8fb86b41 returning error if any.
// Send an offer to purchase a collectible gift »¹, see here »² for the full flow.
//
// Links:
//  1. https://core.telegram.org/api/gifts#collectible-gift-purchase-offers
//  2. https://core.telegram.org/api/gifts#collectible-gift-purchase-offers
//
// Possible errors:
//
//	400 INPUT_STARS_AMOUNT_INVALID:
//	400 INPUT_STARS_NANOS_INVALID:
//	400 INVOICE_INVALID: The specified invoice is invalid.
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//	400 RESELL_STARS_TOO_FEW:
//	400 RESELL_STARS_TOO_MUCH:
//	400 STARGIFT_OFFER_INVALID:
//	400 STARGIFT_OFFER_NOT_ALLOWED:
//	400 STARGIFT_SLUG_INVALID: The specified gift slug is invalid.
//
// See https://core.telegram.org/method/payments.sendStarGiftOffer for reference.
func ( *Client) ( context.Context,  *PaymentsSendStarGiftOfferRequest) (UpdatesClass, error) {
	var  UpdatesBox

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