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

// StoriesGetAlbumStoriesRequest represents TL type `stories.getAlbumStories#ac806d61`.
// Get stories in a story album »¹.
//
// Links:
//  1. https://core.telegram.org/api/stories#story-albums
//
// See https://core.telegram.org/method/stories.getAlbumStories for reference.
type StoriesGetAlbumStoriesRequest struct {
	// Peer where the album is posted.
	Peer InputPeerClass
	// ID of the album.
	AlbumID int
	// Offset for pagination¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	Offset int
	// Maximum number of results to return, see pagination¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	Limit int
}

// StoriesGetAlbumStoriesRequestTypeID is TL type id of StoriesGetAlbumStoriesRequest.
const StoriesGetAlbumStoriesRequestTypeID = 0xac806d61

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

func (g *StoriesGetAlbumStoriesRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Peer == nil) {
		return false
	}
	if !(g.AlbumID == 0) {
		return false
	}
	if !(g.Offset == 0) {
		return false
	}
	if !(g.Limit == 0) {
		return false
	}

	return true
}

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

// FillFrom fills StoriesGetAlbumStoriesRequest from given interface.
func (g *StoriesGetAlbumStoriesRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetAlbumID() (value int)
	GetOffset() (value int)
	GetLimit() (value int)
}) {
	g.Peer = from.GetPeer()
	g.AlbumID = from.GetAlbumID()
	g.Offset = from.GetOffset()
	g.Limit = from.GetLimit()
}

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

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

// TypeInfo returns info about TL type.
func (g *StoriesGetAlbumStoriesRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "stories.getAlbumStories",
		ID:   StoriesGetAlbumStoriesRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "AlbumID",
			SchemaName: "album_id",
		},
		{
			Name:       "Offset",
			SchemaName: "offset",
		},
		{
			Name:       "Limit",
			SchemaName: "limit",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *StoriesGetAlbumStoriesRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode stories.getAlbumStories#ac806d61 as nil")
	}
	b.PutID(StoriesGetAlbumStoriesRequestTypeID)
	return g.EncodeBare(b)
}

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

// Decode implements bin.Decoder.
func (g *StoriesGetAlbumStoriesRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode stories.getAlbumStories#ac806d61 to nil")
	}
	if err := b.ConsumeID(StoriesGetAlbumStoriesRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode stories.getAlbumStories#ac806d61: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *StoriesGetAlbumStoriesRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode stories.getAlbumStories#ac806d61 to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode stories.getAlbumStories#ac806d61: field peer: %w", err)
		}
		g.Peer = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode stories.getAlbumStories#ac806d61: field album_id: %w", err)
		}
		g.AlbumID = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode stories.getAlbumStories#ac806d61: field offset: %w", err)
		}
		g.Offset = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode stories.getAlbumStories#ac806d61: field limit: %w", err)
		}
		g.Limit = value
	}
	return nil
}

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

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

// GetOffset returns value of Offset field.
func (g *StoriesGetAlbumStoriesRequest) GetOffset() (value int) {
	if g == nil {
		return
	}
	return g.Offset
}

// GetLimit returns value of Limit field.
func (g *StoriesGetAlbumStoriesRequest) GetLimit() (value int) {
	if g == nil {
		return
	}
	return g.Limit
}

// StoriesGetAlbumStories invokes method stories.getAlbumStories#ac806d61 returning error if any.
// Get stories in 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.getAlbumStories for reference.
func (c *Client) StoriesGetAlbumStories(ctx context.Context, request *StoriesGetAlbumStoriesRequest) (*StoriesStories, error) {
	var result StoriesStories

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