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

// PaymentsDeleteStarGiftCollectionRequest represents TL type `payments.deleteStarGiftCollection#ad5648e8`.
// Delete a star gift collection »¹.
//
// Links:
//  1. https://core.telegram.org/api/gifts#gift-collections
//
// See https://core.telegram.org/method/payments.deleteStarGiftCollection for reference.
type PaymentsDeleteStarGiftCollectionRequest struct {
	// Peer that owns the collection.
	Peer InputPeerClass
	// ID of the collection.
	CollectionID int
}

// PaymentsDeleteStarGiftCollectionRequestTypeID is TL type id of PaymentsDeleteStarGiftCollectionRequest.
const PaymentsDeleteStarGiftCollectionRequestTypeID = 0xad5648e8

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

func (d *PaymentsDeleteStarGiftCollectionRequest) Zero() bool {
	if d == nil {
		return true
	}
	if !(d.Peer == nil) {
		return false
	}
	if !(d.CollectionID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsDeleteStarGiftCollectionRequest from given interface.
func (d *PaymentsDeleteStarGiftCollectionRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetCollectionID() (value int)
}) {
	d.Peer = from.GetPeer()
	d.CollectionID = from.GetCollectionID()
}

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

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

// TypeInfo returns info about TL type.
func (d *PaymentsDeleteStarGiftCollectionRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "payments.deleteStarGiftCollection",
		ID:   PaymentsDeleteStarGiftCollectionRequestTypeID,
	}
	if d == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "CollectionID",
			SchemaName: "collection_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (d *PaymentsDeleteStarGiftCollectionRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode payments.deleteStarGiftCollection#ad5648e8 as nil")
	}
	b.PutID(PaymentsDeleteStarGiftCollectionRequestTypeID)
	return d.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (d *PaymentsDeleteStarGiftCollectionRequest) EncodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode payments.deleteStarGiftCollection#ad5648e8 as nil")
	}
	if d.Peer == nil {
		return fmt.Errorf("unable to encode payments.deleteStarGiftCollection#ad5648e8: field peer is nil")
	}
	if err := d.Peer.Encode(b); err != nil {
		return fmt.Errorf("unable to encode payments.deleteStarGiftCollection#ad5648e8: field peer: %w", err)
	}
	b.PutInt(d.CollectionID)
	return nil
}

// Decode implements bin.Decoder.
func (d *PaymentsDeleteStarGiftCollectionRequest) Decode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode payments.deleteStarGiftCollection#ad5648e8 to nil")
	}
	if err := b.ConsumeID(PaymentsDeleteStarGiftCollectionRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode payments.deleteStarGiftCollection#ad5648e8: %w", err)
	}
	return d.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (d *PaymentsDeleteStarGiftCollectionRequest) DecodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode payments.deleteStarGiftCollection#ad5648e8 to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode payments.deleteStarGiftCollection#ad5648e8: field peer: %w", err)
		}
		d.Peer = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode payments.deleteStarGiftCollection#ad5648e8: field collection_id: %w", err)
		}
		d.CollectionID = value
	}
	return nil
}

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

// GetCollectionID returns value of CollectionID field.
func (d *PaymentsDeleteStarGiftCollectionRequest) GetCollectionID() (value int) {
	if d == nil {
		return
	}
	return d.CollectionID
}

// PaymentsDeleteStarGiftCollection invokes method payments.deleteStarGiftCollection#ad5648e8 returning error if any.
// Delete a star gift collection »¹.
//
// 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.deleteStarGiftCollection for reference.
func (c *Client) PaymentsDeleteStarGiftCollection(ctx context.Context, request *PaymentsDeleteStarGiftCollectionRequest) (bool, error) {
	var result BoolBox

	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return false, err
	}
	_, ok := result.Bool.(*BoolTrue)
	return ok, nil
}
