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

// ChatlistsGetLeaveChatlistSuggestionsRequest represents TL type `chatlists.getLeaveChatlistSuggestions#fdbcd714`.
// Returns identifiers of pinned or always included chats from a chat folder imported
// using a chat folder deep link »¹, which are suggested to be left when the chat
// folder is deleted.
//
// Links:
//  1. https://core.telegram.org/api/links#chat-folder-links
//
// See https://core.telegram.org/method/chatlists.getLeaveChatlistSuggestions for reference.
type ChatlistsGetLeaveChatlistSuggestionsRequest struct {
	// Folder ID
	Chatlist InputChatlistDialogFilter
}

// ChatlistsGetLeaveChatlistSuggestionsRequestTypeID is TL type id of ChatlistsGetLeaveChatlistSuggestionsRequest.
const ChatlistsGetLeaveChatlistSuggestionsRequestTypeID = 0xfdbcd714

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

func (g *ChatlistsGetLeaveChatlistSuggestionsRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Chatlist.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills ChatlistsGetLeaveChatlistSuggestionsRequest from given interface.
func (g *ChatlistsGetLeaveChatlistSuggestionsRequest) FillFrom(from interface {
	GetChatlist() (value InputChatlistDialogFilter)
}) {
	g.Chatlist = from.GetChatlist()
}

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

// TypeName returns name of type in TL schema.
func (*ChatlistsGetLeaveChatlistSuggestionsRequest) TypeName() string {
	return "chatlists.getLeaveChatlistSuggestions"
}

// TypeInfo returns info about TL type.
func (g *ChatlistsGetLeaveChatlistSuggestionsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "chatlists.getLeaveChatlistSuggestions",
		ID:   ChatlistsGetLeaveChatlistSuggestionsRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Chatlist",
			SchemaName: "chatlist",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *ChatlistsGetLeaveChatlistSuggestionsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode chatlists.getLeaveChatlistSuggestions#fdbcd714 as nil")
	}
	b.PutID(ChatlistsGetLeaveChatlistSuggestionsRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *ChatlistsGetLeaveChatlistSuggestionsRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode chatlists.getLeaveChatlistSuggestions#fdbcd714 as nil")
	}
	if err := g.Chatlist.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatlists.getLeaveChatlistSuggestions#fdbcd714: field chatlist: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (g *ChatlistsGetLeaveChatlistSuggestionsRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode chatlists.getLeaveChatlistSuggestions#fdbcd714 to nil")
	}
	if err := b.ConsumeID(ChatlistsGetLeaveChatlistSuggestionsRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode chatlists.getLeaveChatlistSuggestions#fdbcd714: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *ChatlistsGetLeaveChatlistSuggestionsRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode chatlists.getLeaveChatlistSuggestions#fdbcd714 to nil")
	}
	{
		if err := g.Chatlist.Decode(b); err != nil {
			return fmt.Errorf("unable to decode chatlists.getLeaveChatlistSuggestions#fdbcd714: field chatlist: %w", err)
		}
	}
	return nil
}

// GetChatlist returns value of Chatlist field.
func (g *ChatlistsGetLeaveChatlistSuggestionsRequest) GetChatlist() (value InputChatlistDialogFilter) {
	if g == nil {
		return
	}
	return g.Chatlist
}

// ChatlistsGetLeaveChatlistSuggestions invokes method chatlists.getLeaveChatlistSuggestions#fdbcd714 returning error if any.
// Returns identifiers of pinned or always included chats from a chat folder imported
// using a chat folder deep link »¹, which are suggested to be left when the chat
// folder is deleted.
//
// Links:
//  1. https://core.telegram.org/api/links#chat-folder-links
//
// Possible errors:
//
//	400 FILTER_ID_INVALID: The specified filter ID is invalid.
//	400 FILTER_NOT_SUPPORTED: The specified filter cannot be used in this context.
//
// See https://core.telegram.org/method/chatlists.getLeaveChatlistSuggestions for reference.
func (c *Client) ChatlistsGetLeaveChatlistSuggestions(ctx context.Context, chatlist InputChatlistDialogFilter) ([]PeerClass, error) {
	var result PeerClassVector

	request := &ChatlistsGetLeaveChatlistSuggestionsRequest{
		Chatlist: chatlist,
	}
	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return nil, err
	}
	return []PeerClass(result.Elems), nil
}
