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

// PaymentsGetStarGiftCollectionsRequest represents TL type `payments.getStarGiftCollections#981b91dd`.
// Fetches all star gift collections »¹ of a peer.
//
// Links:
//  1. https://core.telegram.org/api/gifts#gift-collections
//
// See https://core.telegram.org/method/payments.getStarGiftCollections for reference.
type PaymentsGetStarGiftCollectionsRequest struct {
	// The peer.
	Peer InputPeerClass
	// Hash (generated as specified here »¹) using the starGiftCollection².hash field (not
	// the collection_id field) of all collections returned by a previous method call, to
	// avoid refetching the result if it hasn't changed.
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets#hash-generation
	//  2) https://core.telegram.org/constructor/starGiftCollection
	Hash int64
}

// PaymentsGetStarGiftCollectionsRequestTypeID is TL type id of PaymentsGetStarGiftCollectionsRequest.
const PaymentsGetStarGiftCollectionsRequestTypeID = 0x981b91dd

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

func (g *PaymentsGetStarGiftCollectionsRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Peer == nil) {
		return false
	}
	if !(g.Hash == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsGetStarGiftCollectionsRequest from given interface.
func (g *PaymentsGetStarGiftCollectionsRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetHash() (value int64)
}) {
	g.Peer = from.GetPeer()
	g.Hash = from.GetHash()
}

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

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

// TypeInfo returns info about TL type.
func (g *PaymentsGetStarGiftCollectionsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "payments.getStarGiftCollections",
		ID:   PaymentsGetStarGiftCollectionsRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "Hash",
			SchemaName: "hash",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *PaymentsGetStarGiftCollectionsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode payments.getStarGiftCollections#981b91dd as nil")
	}
	b.PutID(PaymentsGetStarGiftCollectionsRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *PaymentsGetStarGiftCollectionsRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode payments.getStarGiftCollections#981b91dd as nil")
	}
	if g.Peer == nil {
		return fmt.Errorf("unable to encode payments.getStarGiftCollections#981b91dd: field peer is nil")
	}
	if err := g.Peer.Encode(b); err != nil {
		return fmt.Errorf("unable to encode payments.getStarGiftCollections#981b91dd: field peer: %w", err)
	}
	b.PutLong(g.Hash)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *PaymentsGetStarGiftCollectionsRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode payments.getStarGiftCollections#981b91dd to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode payments.getStarGiftCollections#981b91dd: field peer: %w", err)
		}
		g.Peer = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode payments.getStarGiftCollections#981b91dd: field hash: %w", err)
		}
		g.Hash = value
	}
	return nil
}

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

// GetHash returns value of Hash field.
func (g *PaymentsGetStarGiftCollectionsRequest) GetHash() (value int64) {
	if g == nil {
		return
	}
	return g.Hash
}

// PaymentsGetStarGiftCollections invokes method payments.getStarGiftCollections#981b91dd returning error if any.
// Fetches all star gift collections »¹ of a peer.
//
// Links:
//  1. https://core.telegram.org/api/gifts#gift-collections
//
// Possible errors:
//
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//
// See https://core.telegram.org/method/payments.getStarGiftCollections for reference.
func (c *Client) PaymentsGetStarGiftCollections(ctx context.Context, request *PaymentsGetStarGiftCollectionsRequest) (PaymentsStarGiftCollectionsClass, error) {
	var result PaymentsStarGiftCollectionsBox

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