// Code generated by gotdgen, DO NOT EDIT.

package tdapi

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

// GetChatsToPostStoriesRequest represents TL type `getChatsToPostStories#70e2a473`.
type GetChatsToPostStoriesRequest struct {
}

// GetChatsToPostStoriesRequestTypeID is TL type id of GetChatsToPostStoriesRequest.
const GetChatsToPostStoriesRequestTypeID = 0x70e2a473

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

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

	return true
}

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

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

// TypeName returns name of type in TL schema.
func (*GetChatsToPostStoriesRequest) TypeName() string {
	return "getChatsToPostStories"
}

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

// Encode implements bin.Encoder.
func (g *GetChatsToPostStoriesRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getChatsToPostStories#70e2a473 as nil")
	}
	b.PutID(GetChatsToPostStoriesRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetChatsToPostStoriesRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getChatsToPostStories#70e2a473 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (g *GetChatsToPostStoriesRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getChatsToPostStories#70e2a473 to nil")
	}
	if err := b.ConsumeID(GetChatsToPostStoriesRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode getChatsToPostStories#70e2a473: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *GetChatsToPostStoriesRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getChatsToPostStories#70e2a473 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetChatsToPostStoriesRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getChatsToPostStories#70e2a473 as nil")
	}
	b.ObjStart()
	b.PutID("getChatsToPostStories")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GetChatsToPostStoriesRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if g == nil {
		return fmt.Errorf("can't decode getChatsToPostStories#70e2a473 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getChatsToPostStories"); err != nil {
				return fmt.Errorf("unable to decode getChatsToPostStories#70e2a473: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetChatsToPostStories invokes method getChatsToPostStories#70e2a473 returning error if any.
func (c *Client) GetChatsToPostStories(ctx context.Context) (*Chats, error) {
	var result Chats

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