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

// PaymentsGetUniqueStarGiftRequest represents TL type `payments.getUniqueStarGift#a1974d72`.
// Obtain info about a collectible gift »¹ using a slug obtained from a collectible
// gift link »².
//
// Links:
//  1. https://core.telegram.org/api/gifts#collectible-gifts
//  2. https://core.telegram.org/api/links#collectible-gift-link
//
// See https://core.telegram.org/method/payments.getUniqueStarGift for reference.
type PaymentsGetUniqueStarGiftRequest struct {
	// The slug.
	Slug string
}

// PaymentsGetUniqueStarGiftRequestTypeID is TL type id of PaymentsGetUniqueStarGiftRequest.
const PaymentsGetUniqueStarGiftRequestTypeID = 0xa1974d72

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

func (g *PaymentsGetUniqueStarGiftRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Slug == "") {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsGetUniqueStarGiftRequest from given interface.
func (g *PaymentsGetUniqueStarGiftRequest) FillFrom(from interface {
	GetSlug() (value string)
}) {
	g.Slug = from.GetSlug()
}

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

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

// TypeInfo returns info about TL type.
func (g *PaymentsGetUniqueStarGiftRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "payments.getUniqueStarGift",
		ID:   PaymentsGetUniqueStarGiftRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Slug",
			SchemaName: "slug",
		},
	}
	return typ
}

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

// EncodeBare implements bin.BareEncoder.
func (g *PaymentsGetUniqueStarGiftRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode payments.getUniqueStarGift#a1974d72 as nil")
	}
	b.PutString(g.Slug)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *PaymentsGetUniqueStarGiftRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode payments.getUniqueStarGift#a1974d72 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode payments.getUniqueStarGift#a1974d72: field slug: %w", err)
		}
		g.Slug = value
	}
	return nil
}

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

// PaymentsGetUniqueStarGift invokes method payments.getUniqueStarGift#a1974d72 returning error if any.
// Obtain info about a collectible gift »¹ using a slug obtained from a collectible
// gift link »².
//
// Links:
//  1. https://core.telegram.org/api/gifts#collectible-gifts
//  2. https://core.telegram.org/api/links#collectible-gift-link
//
// Possible errors:
//
//	400 STARGIFT_SLUG_INVALID: The specified gift slug is invalid.
//
// See https://core.telegram.org/method/payments.getUniqueStarGift for reference.
func (c *Client) PaymentsGetUniqueStarGift(ctx context.Context, slug string) (*PaymentsUniqueStarGift, error) {
	var result PaymentsUniqueStarGift

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