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

// ToggleGeneralForumTopicIsHiddenRequest represents TL type `toggleGeneralForumTopicIsHidden#5f1d1448`.
type ToggleGeneralForumTopicIsHiddenRequest struct {
	// Identifier of the chat
	ChatID int64
	// Pass true to hide and close the General topic; pass false to unhide it
	IsHidden bool
}

// ToggleGeneralForumTopicIsHiddenRequestTypeID is TL type id of ToggleGeneralForumTopicIsHiddenRequest.
const ToggleGeneralForumTopicIsHiddenRequestTypeID = 0x5f1d1448

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

func (t *ToggleGeneralForumTopicIsHiddenRequest) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.ChatID == 0) {
		return false
	}
	if !(t.IsHidden == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *ToggleGeneralForumTopicIsHiddenRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "toggleGeneralForumTopicIsHidden",
		ID:   ToggleGeneralForumTopicIsHiddenRequestTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "IsHidden",
			SchemaName: "is_hidden",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *ToggleGeneralForumTopicIsHiddenRequest) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleGeneralForumTopicIsHidden#5f1d1448 as nil")
	}
	b.PutID(ToggleGeneralForumTopicIsHiddenRequestTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *ToggleGeneralForumTopicIsHiddenRequest) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleGeneralForumTopicIsHidden#5f1d1448 as nil")
	}
	b.PutInt53(t.ChatID)
	b.PutBool(t.IsHidden)
	return nil
}

// Decode implements bin.Decoder.
func (t *ToggleGeneralForumTopicIsHiddenRequest) Decode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleGeneralForumTopicIsHidden#5f1d1448 to nil")
	}
	if err := b.ConsumeID(ToggleGeneralForumTopicIsHiddenRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode toggleGeneralForumTopicIsHidden#5f1d1448: %w", err)
	}
	return t.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (t *ToggleGeneralForumTopicIsHiddenRequest) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleGeneralForumTopicIsHidden#5f1d1448 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode toggleGeneralForumTopicIsHidden#5f1d1448: field chat_id: %w", err)
		}
		t.ChatID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode toggleGeneralForumTopicIsHidden#5f1d1448: field is_hidden: %w", err)
		}
		t.IsHidden = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *ToggleGeneralForumTopicIsHiddenRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleGeneralForumTopicIsHidden#5f1d1448 as nil")
	}
	b.ObjStart()
	b.PutID("toggleGeneralForumTopicIsHidden")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(t.ChatID)
	b.Comma()
	b.FieldStart("is_hidden")
	b.PutBool(t.IsHidden)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (t *ToggleGeneralForumTopicIsHiddenRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleGeneralForumTopicIsHidden#5f1d1448 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("toggleGeneralForumTopicIsHidden"); err != nil {
				return fmt.Errorf("unable to decode toggleGeneralForumTopicIsHidden#5f1d1448: %w", err)
			}
		case "chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode toggleGeneralForumTopicIsHidden#5f1d1448: field chat_id: %w", err)
			}
			t.ChatID = value
		case "is_hidden":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode toggleGeneralForumTopicIsHidden#5f1d1448: field is_hidden: %w", err)
			}
			t.IsHidden = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetChatID returns value of ChatID field.
func (t *ToggleGeneralForumTopicIsHiddenRequest) GetChatID() (value int64) {
	if t == nil {
		return
	}
	return t.ChatID
}

// GetIsHidden returns value of IsHidden field.
func (t *ToggleGeneralForumTopicIsHiddenRequest) GetIsHidden() (value bool) {
	if t == nil {
		return
	}
	return t.IsHidden
}

// ToggleGeneralForumTopicIsHidden invokes method toggleGeneralForumTopicIsHidden#5f1d1448 returning error if any.
func (c *Client) ToggleGeneralForumTopicIsHidden(ctx context.Context, request *ToggleGeneralForumTopicIsHiddenRequest) error {
	var ok Ok

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