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

// ChatlistsHideChatlistUpdatesRequest represents TL type `chatlists.hideChatlistUpdates#66e486fb`.
// Dismiss new pending peers recently added to a chat folder deep link »¹.
//
// Links:
//  1. https://core.telegram.org/api/links#chat-folder-links
//
// See https://core.telegram.org/method/chatlists.hideChatlistUpdates for reference.
type ChatlistsHideChatlistUpdatesRequest struct {
	// The folder
	Chatlist InputChatlistDialogFilter
}

// ChatlistsHideChatlistUpdatesRequestTypeID is TL type id of ChatlistsHideChatlistUpdatesRequest.
const ChatlistsHideChatlistUpdatesRequestTypeID = 0x66e486fb

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

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

	return true
}

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

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

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

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

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

// Encode implements bin.Encoder.
func (h *ChatlistsHideChatlistUpdatesRequest) Encode(b *bin.Buffer) error {
	if h == nil {
		return fmt.Errorf("can't encode chatlists.hideChatlistUpdates#66e486fb as nil")
	}
	b.PutID(ChatlistsHideChatlistUpdatesRequestTypeID)
	return h.EncodeBare(b)
}

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

// Decode implements bin.Decoder.
func (h *ChatlistsHideChatlistUpdatesRequest) Decode(b *bin.Buffer) error {
	if h == nil {
		return fmt.Errorf("can't decode chatlists.hideChatlistUpdates#66e486fb to nil")
	}
	if err := b.ConsumeID(ChatlistsHideChatlistUpdatesRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode chatlists.hideChatlistUpdates#66e486fb: %w", err)
	}
	return h.DecodeBare(b)
}

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

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

// ChatlistsHideChatlistUpdates invokes method chatlists.hideChatlistUpdates#66e486fb returning error if any.
// Dismiss new pending peers recently added to a chat folder deep link »¹.
//
// 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.hideChatlistUpdates for reference.
func (c *Client) ChatlistsHideChatlistUpdates(ctx context.Context, chatlist InputChatlistDialogFilter) (bool, error) {
	var result BoolBox

	request := &ChatlistsHideChatlistUpdatesRequest{
		Chatlist: chatlist,
	}
	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return false, err
	}
	_, ok := result.Bool.(*BoolTrue)
	return ok, nil
}
