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

// MessagesToggleDialogFilterTagsRequest represents TL type `messages.toggleDialogFilterTags#fd2dda49`.
// Enable or disable folder tags »¹.
//
// Links:
//  1. https://core.telegram.org/api/folders#folder-tags
//
// See https://core.telegram.org/method/messages.toggleDialogFilterTags for reference.
type MessagesToggleDialogFilterTagsRequest struct {
	// Enable or disable folder tags.
	Enabled bool
}

// MessagesToggleDialogFilterTagsRequestTypeID is TL type id of MessagesToggleDialogFilterTagsRequest.
const MessagesToggleDialogFilterTagsRequestTypeID = 0xfd2dda49

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

func (t *MessagesToggleDialogFilterTagsRequest) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.Enabled == false) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesToggleDialogFilterTagsRequest from given interface.
func (t *MessagesToggleDialogFilterTagsRequest) FillFrom(from interface {
	GetEnabled() (value bool)
}) {
	t.Enabled = from.GetEnabled()
}

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

// TypeName returns name of type in TL schema.
func (*MessagesToggleDialogFilterTagsRequest) TypeName() string {
	return "messages.toggleDialogFilterTags"
}

// TypeInfo returns info about TL type.
func (t *MessagesToggleDialogFilterTagsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.toggleDialogFilterTags",
		ID:   MessagesToggleDialogFilterTagsRequestTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Enabled",
			SchemaName: "enabled",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *MessagesToggleDialogFilterTagsRequest) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode messages.toggleDialogFilterTags#fd2dda49 as nil")
	}
	b.PutID(MessagesToggleDialogFilterTagsRequestTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *MessagesToggleDialogFilterTagsRequest) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode messages.toggleDialogFilterTags#fd2dda49 as nil")
	}
	b.PutBool(t.Enabled)
	return nil
}

// Decode implements bin.Decoder.
func (t *MessagesToggleDialogFilterTagsRequest) Decode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode messages.toggleDialogFilterTags#fd2dda49 to nil")
	}
	if err := b.ConsumeID(MessagesToggleDialogFilterTagsRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.toggleDialogFilterTags#fd2dda49: %w", err)
	}
	return t.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (t *MessagesToggleDialogFilterTagsRequest) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode messages.toggleDialogFilterTags#fd2dda49 to nil")
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode messages.toggleDialogFilterTags#fd2dda49: field enabled: %w", err)
		}
		t.Enabled = value
	}
	return nil
}

// GetEnabled returns value of Enabled field.
func (t *MessagesToggleDialogFilterTagsRequest) GetEnabled() (value bool) {
	if t == nil {
		return
	}
	return t.Enabled
}

// MessagesToggleDialogFilterTags invokes method messages.toggleDialogFilterTags#fd2dda49 returning error if any.
// Enable or disable folder tags »¹.
//
// Links:
//  1. https://core.telegram.org/api/folders#folder-tags
//
// Possible errors:
//
//	403 PREMIUM_ACCOUNT_REQUIRED: A premium account is required to execute this action.
//
// See https://core.telegram.org/method/messages.toggleDialogFilterTags for reference.
func (c *Client) MessagesToggleDialogFilterTags(ctx context.Context, enabled bool) (bool, error) {
	var result BoolBox

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