// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdjson"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdp"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
)

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

// PaymentsCheckCanSendGiftRequest represents TL type `payments.checkCanSendGift#c0c4edc9`.
// Check if the specified gift »¹ can be sent.
//
// Links:
//  1. https://core.telegram.org/api/gifts
//
// See https://core.telegram.org/method/payments.checkCanSendGift for reference.
type PaymentsCheckCanSendGiftRequest struct {
	// Gift ID.
	GiftID int64
}

// PaymentsCheckCanSendGiftRequestTypeID is TL type id of PaymentsCheckCanSendGiftRequest.
const PaymentsCheckCanSendGiftRequestTypeID = 0xc0c4edc9

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

func (c *PaymentsCheckCanSendGiftRequest) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.GiftID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsCheckCanSendGiftRequest from given interface.
func (c *PaymentsCheckCanSendGiftRequest) FillFrom(from interface {
	GetGiftID() (value int64)
}) {
	c.GiftID = from.GetGiftID()
}

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

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

// TypeInfo returns info about TL type.
func (c *PaymentsCheckCanSendGiftRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "payments.checkCanSendGift",
		ID:   PaymentsCheckCanSendGiftRequestTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "GiftID",
			SchemaName: "gift_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *PaymentsCheckCanSendGiftRequest) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode payments.checkCanSendGift#c0c4edc9 as nil")
	}
	b.PutID(PaymentsCheckCanSendGiftRequestTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *PaymentsCheckCanSendGiftRequest) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode payments.checkCanSendGift#c0c4edc9 as nil")
	}
	b.PutLong(c.GiftID)
	return nil
}

// Decode implements bin.Decoder.
func (c *PaymentsCheckCanSendGiftRequest) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode payments.checkCanSendGift#c0c4edc9 to nil")
	}
	if err := b.ConsumeID(PaymentsCheckCanSendGiftRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode payments.checkCanSendGift#c0c4edc9: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *PaymentsCheckCanSendGiftRequest) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode payments.checkCanSendGift#c0c4edc9 to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode payments.checkCanSendGift#c0c4edc9: field gift_id: %w", err)
		}
		c.GiftID = value
	}
	return nil
}

// GetGiftID returns value of GiftID field.
func (c *PaymentsCheckCanSendGiftRequest) GetGiftID() (value int64) {
	if c == nil {
		return
	}
	return c.GiftID
}

// PaymentsCheckCanSendGift invokes method payments.checkCanSendGift#c0c4edc9 returning error if any.
// Check if the specified gift »¹ can be sent.
//
// Links:
//  1. https://core.telegram.org/api/gifts
//
// Possible errors:
//
//	400 STARGIFT_INVALID: The passed gift is invalid.
//
// See https://core.telegram.org/method/payments.checkCanSendGift for reference.
func (c *Client) PaymentsCheckCanSendGift(ctx context.Context, giftid int64) (PaymentsCheckCanSendGiftResultClass, error) {
	var result PaymentsCheckCanSendGiftResultBox

	request := &PaymentsCheckCanSendGiftRequest{
		GiftID: giftid,
	}
	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return nil, err
	}
	return result.CheckCanSendGiftResult, nil
}
