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

// PaymentsGetCraftStarGiftsRequest represents TL type `payments.getCraftStarGifts#fd05dd00`.
//
// See https://core.telegram.org/method/payments.getCraftStarGifts for reference.
type PaymentsGetCraftStarGiftsRequest struct {
	// GiftID field of PaymentsGetCraftStarGiftsRequest.
	GiftID int64
	// Offset field of PaymentsGetCraftStarGiftsRequest.
	Offset string
	// Limit field of PaymentsGetCraftStarGiftsRequest.
	Limit int
}

// PaymentsGetCraftStarGiftsRequestTypeID is TL type id of PaymentsGetCraftStarGiftsRequest.
const PaymentsGetCraftStarGiftsRequestTypeID = 0xfd05dd00

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

func (g *PaymentsGetCraftStarGiftsRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.GiftID == 0) {
		return false
	}
	if !(g.Offset == "") {
		return false
	}
	if !(g.Limit == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsGetCraftStarGiftsRequest from given interface.
func (g *PaymentsGetCraftStarGiftsRequest) FillFrom(from interface {
	GetGiftID() (value int64)
	GetOffset() (value string)
	GetLimit() (value int)
}) {
	g.GiftID = from.GetGiftID()
	g.Offset = from.GetOffset()
	g.Limit = from.GetLimit()
}

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

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

// TypeInfo returns info about TL type.
func (g *PaymentsGetCraftStarGiftsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "payments.getCraftStarGifts",
		ID:   PaymentsGetCraftStarGiftsRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "GiftID",
			SchemaName: "gift_id",
		},
		{
			Name:       "Offset",
			SchemaName: "offset",
		},
		{
			Name:       "Limit",
			SchemaName: "limit",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *PaymentsGetCraftStarGiftsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode payments.getCraftStarGifts#fd05dd00 as nil")
	}
	b.PutID(PaymentsGetCraftStarGiftsRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *PaymentsGetCraftStarGiftsRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode payments.getCraftStarGifts#fd05dd00 as nil")
	}
	b.PutLong(g.GiftID)
	b.PutString(g.Offset)
	b.PutInt(g.Limit)
	return nil
}

// Decode implements bin.Decoder.
func (g *PaymentsGetCraftStarGiftsRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode payments.getCraftStarGifts#fd05dd00 to nil")
	}
	if err := b.ConsumeID(PaymentsGetCraftStarGiftsRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode payments.getCraftStarGifts#fd05dd00: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *PaymentsGetCraftStarGiftsRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode payments.getCraftStarGifts#fd05dd00 to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode payments.getCraftStarGifts#fd05dd00: field gift_id: %w", err)
		}
		g.GiftID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode payments.getCraftStarGifts#fd05dd00: field offset: %w", err)
		}
		g.Offset = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode payments.getCraftStarGifts#fd05dd00: field limit: %w", err)
		}
		g.Limit = value
	}
	return nil
}

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

// GetOffset returns value of Offset field.
func (g *PaymentsGetCraftStarGiftsRequest) GetOffset() (value string) {
	if g == nil {
		return
	}
	return g.Offset
}

// GetLimit returns value of Limit field.
func (g *PaymentsGetCraftStarGiftsRequest) GetLimit() (value int) {
	if g == nil {
		return
	}
	return g.Limit
}

// PaymentsGetCraftStarGifts invokes method payments.getCraftStarGifts#fd05dd00 returning error if any.
//
// See https://core.telegram.org/method/payments.getCraftStarGifts for reference.
func (c *Client) PaymentsGetCraftStarGifts(ctx context.Context, request *PaymentsGetCraftStarGiftsRequest) (*PaymentsSavedStarGifts, error) {
	var result PaymentsSavedStarGifts

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