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

// ToggleChatFolderTagsRequest represents TL type `toggleChatFolderTags#834b6c44`.
type ToggleChatFolderTagsRequest struct {
	// Pass true to enable folder tags; pass false to disable them
	AreTagsEnabled bool
}

// ToggleChatFolderTagsRequestTypeID is TL type id of ToggleChatFolderTagsRequest.
const ToggleChatFolderTagsRequestTypeID = 0x834b6c44

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

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *ToggleChatFolderTagsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "toggleChatFolderTags",
		ID:   ToggleChatFolderTagsRequestTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "AreTagsEnabled",
			SchemaName: "are_tags_enabled",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *ToggleChatFolderTagsRequest) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleChatFolderTags#834b6c44 as nil")
	}
	b.PutID(ToggleChatFolderTagsRequestTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *ToggleChatFolderTagsRequest) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleChatFolderTags#834b6c44 as nil")
	}
	b.PutBool(t.AreTagsEnabled)
	return nil
}

// Decode implements bin.Decoder.
func (t *ToggleChatFolderTagsRequest) Decode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleChatFolderTags#834b6c44 to nil")
	}
	if err := b.ConsumeID(ToggleChatFolderTagsRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode toggleChatFolderTags#834b6c44: %w", err)
	}
	return t.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (t *ToggleChatFolderTagsRequest) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleChatFolderTags#834b6c44 to nil")
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode toggleChatFolderTags#834b6c44: field are_tags_enabled: %w", err)
		}
		t.AreTagsEnabled = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *ToggleChatFolderTagsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleChatFolderTags#834b6c44 as nil")
	}
	b.ObjStart()
	b.PutID("toggleChatFolderTags")
	b.Comma()
	b.FieldStart("are_tags_enabled")
	b.PutBool(t.AreTagsEnabled)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (t *ToggleChatFolderTagsRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleChatFolderTags#834b6c44 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("toggleChatFolderTags"); err != nil {
				return fmt.Errorf("unable to decode toggleChatFolderTags#834b6c44: %w", err)
			}
		case "are_tags_enabled":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode toggleChatFolderTags#834b6c44: field are_tags_enabled: %w", err)
			}
			t.AreTagsEnabled = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetAreTagsEnabled returns value of AreTagsEnabled field.
func (t *ToggleChatFolderTagsRequest) GetAreTagsEnabled() (value bool) {
	if t == nil {
		return
	}
	return t.AreTagsEnabled
}

// ToggleChatFolderTags invokes method toggleChatFolderTags#834b6c44 returning error if any.
func (c *Client) ToggleChatFolderTags(ctx context.Context, aretagsenabled bool) error {
	var ok Ok

	request := &ToggleChatFolderTagsRequest{
		AreTagsEnabled: aretagsenabled,
	}
	if err := c.rpc.Invoke(ctx, request, &ok); err != nil {
		return err
	}
	return nil
}
