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

// PaymentsGetUniqueStarGiftValueInfoRequest represents TL type `payments.getUniqueStarGiftValueInfo#4365af6b`.
// Get information about the value of a collectible gift »¹.
//
// Links:
//  1. https://core.telegram.org/api/gifts#collectible-gifts
//
// See https://core.telegram.org/method/payments.getUniqueStarGiftValueInfo for reference.
type PaymentsGetUniqueStarGiftValueInfoRequest struct {
	// slug from a starGiftUnique¹.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/starGiftUnique
	Slug string
}

// PaymentsGetUniqueStarGiftValueInfoRequestTypeID is TL type id of PaymentsGetUniqueStarGiftValueInfoRequest.
const PaymentsGetUniqueStarGiftValueInfoRequestTypeID = 0x4365af6b

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

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

	return true
}

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

// FillFrom fills PaymentsGetUniqueStarGiftValueInfoRequest from given interface.
func (g *PaymentsGetUniqueStarGiftValueInfoRequest) 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 (*PaymentsGetUniqueStarGiftValueInfoRequest) TypeID() uint32 {
	return PaymentsGetUniqueStarGiftValueInfoRequestTypeID
}

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

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

// Encode implements bin.Encoder.
func (g *PaymentsGetUniqueStarGiftValueInfoRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode payments.getUniqueStarGiftValueInfo#4365af6b as nil")
	}
	b.PutID(PaymentsGetUniqueStarGiftValueInfoRequestTypeID)
	return g.EncodeBare(b)
}

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

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

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

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

// PaymentsGetUniqueStarGiftValueInfo invokes method payments.getUniqueStarGiftValueInfo#4365af6b returning error if any.
// Get information about the value of a collectible gift »¹.
//
// Links:
//  1. https://core.telegram.org/api/gifts#collectible-gifts
//
// Possible errors:
//
//	400 STARGIFT_SLUG_INVALID: The specified gift slug is invalid.
//
// See https://core.telegram.org/method/payments.getUniqueStarGiftValueInfo for reference.
func (c *Client) PaymentsGetUniqueStarGiftValueInfo(ctx context.Context, slug string) (*PaymentsUniqueStarGiftValueInfo, error) {
	var result PaymentsUniqueStarGiftValueInfo

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