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

// StoriesGetChatsToSendRequest represents TL type `stories.getChatsToSend#a56a8b60`.
// Obtain a list of channels where the user can post stories¹
//
// Links:
//  1. https://core.telegram.org/api/stories
//
// See https://core.telegram.org/method/stories.getChatsToSend for reference.
type StoriesGetChatsToSendRequest struct {
}

// StoriesGetChatsToSendRequestTypeID is TL type id of StoriesGetChatsToSendRequest.
const StoriesGetChatsToSendRequestTypeID = 0xa56a8b60

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

func (g *StoriesGetChatsToSendRequest) Zero() bool {
	if g == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *StoriesGetChatsToSendRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "stories.getChatsToSend",
		ID:   StoriesGetChatsToSendRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

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

// EncodeBare implements bin.BareEncoder.
func (g *StoriesGetChatsToSendRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode stories.getChatsToSend#a56a8b60 as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *StoriesGetChatsToSendRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode stories.getChatsToSend#a56a8b60 to nil")
	}
	return nil
}

// StoriesGetChatsToSend invokes method stories.getChatsToSend#a56a8b60 returning error if any.
// Obtain a list of channels where the user can post stories¹
//
// Links:
//  1. https://core.telegram.org/api/stories
//
// See https://core.telegram.org/method/stories.getChatsToSend for reference.
func (c *Client) StoriesGetChatsToSend(ctx context.Context) (MessagesChatsClass, error) {
	var result MessagesChatsBox

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