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

// StoriesDeleteAlbumRequest represents TL type `stories.deleteAlbum#8d3456d0`.
// Delete a story album¹.
//
// Links:
//  1. https://core.telegram.org/api/stories#story-albums
//
// See https://core.telegram.org/method/stories.deleteAlbum for reference.
type StoriesDeleteAlbumRequest struct {
	// Owned peer where the album is located.
	Peer InputPeerClass
	// ID of the album to delete.
	AlbumID int
}

// StoriesDeleteAlbumRequestTypeID is TL type id of StoriesDeleteAlbumRequest.
const StoriesDeleteAlbumRequestTypeID = 0x8d3456d0

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

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

	return true
}

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

// FillFrom fills StoriesDeleteAlbumRequest from given interface.
func (d *StoriesDeleteAlbumRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetAlbumID() (value int)
}) {
	d.Peer = from.GetPeer()
	d.AlbumID = from.GetAlbumID()
}

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

// TypeName returns name of type in TL schema.
func (*StoriesDeleteAlbumRequest) TypeName() string {
	return "stories.deleteAlbum"
}

// TypeInfo returns info about TL type.
func (d *StoriesDeleteAlbumRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "stories.deleteAlbum",
		ID:   StoriesDeleteAlbumRequestTypeID,
	}
	if d == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "AlbumID",
			SchemaName: "album_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (d *StoriesDeleteAlbumRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode stories.deleteAlbum#8d3456d0 as nil")
	}
	b.PutID(StoriesDeleteAlbumRequestTypeID)
	return d.EncodeBare(b)
}

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

// Decode implements bin.Decoder.
func (d *StoriesDeleteAlbumRequest) Decode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode stories.deleteAlbum#8d3456d0 to nil")
	}
	if err := b.ConsumeID(StoriesDeleteAlbumRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode stories.deleteAlbum#8d3456d0: %w", err)
	}
	return d.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (d *StoriesDeleteAlbumRequest) DecodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode stories.deleteAlbum#8d3456d0 to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode stories.deleteAlbum#8d3456d0: field peer: %w", err)
		}
		d.Peer = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode stories.deleteAlbum#8d3456d0: field album_id: %w", err)
		}
		d.AlbumID = value
	}
	return nil
}

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

// GetAlbumID returns value of AlbumID field.
func (d *StoriesDeleteAlbumRequest) GetAlbumID() (value int) {
	if d == nil {
		return
	}
	return d.AlbumID
}

// StoriesDeleteAlbum invokes method stories.deleteAlbum#8d3456d0 returning error if any.
// Delete a story album¹.
//
// Links:
//  1. https://core.telegram.org/api/stories#story-albums
//
// Possible errors:
//
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//
// See https://core.telegram.org/method/stories.deleteAlbum for reference.
func (c *Client) StoriesDeleteAlbum(ctx context.Context, request *StoriesDeleteAlbumRequest) (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
}
