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

// ToggleSupergroupIsForumRequest represents TL type `toggleSupergroupIsForum#161dfe11`.
type ToggleSupergroupIsForumRequest struct {
	// Identifier of the supergroup
	SupergroupID int64
	// New value of is_forum
	IsForum bool
	// New value of has_forum_tabs; ignored if is_forum is false
	HasForumTabs bool
}

// ToggleSupergroupIsForumRequestTypeID is TL type id of ToggleSupergroupIsForumRequest.
const ToggleSupergroupIsForumRequestTypeID = 0x161dfe11

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

func (t *ToggleSupergroupIsForumRequest) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.SupergroupID == 0) {
		return false
	}
	if !(t.IsForum == false) {
		return false
	}
	if !(t.HasForumTabs == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *ToggleSupergroupIsForumRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "toggleSupergroupIsForum",
		ID:   ToggleSupergroupIsForumRequestTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "SupergroupID",
			SchemaName: "supergroup_id",
		},
		{
			Name:       "IsForum",
			SchemaName: "is_forum",
		},
		{
			Name:       "HasForumTabs",
			SchemaName: "has_forum_tabs",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *ToggleSupergroupIsForumRequest) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleSupergroupIsForum#161dfe11 as nil")
	}
	b.PutID(ToggleSupergroupIsForumRequestTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *ToggleSupergroupIsForumRequest) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleSupergroupIsForum#161dfe11 as nil")
	}
	b.PutInt53(t.SupergroupID)
	b.PutBool(t.IsForum)
	b.PutBool(t.HasForumTabs)
	return nil
}

// Decode implements bin.Decoder.
func (t *ToggleSupergroupIsForumRequest) Decode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleSupergroupIsForum#161dfe11 to nil")
	}
	if err := b.ConsumeID(ToggleSupergroupIsForumRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode toggleSupergroupIsForum#161dfe11: %w", err)
	}
	return t.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (t *ToggleSupergroupIsForumRequest) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleSupergroupIsForum#161dfe11 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode toggleSupergroupIsForum#161dfe11: field supergroup_id: %w", err)
		}
		t.SupergroupID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode toggleSupergroupIsForum#161dfe11: field is_forum: %w", err)
		}
		t.IsForum = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode toggleSupergroupIsForum#161dfe11: field has_forum_tabs: %w", err)
		}
		t.HasForumTabs = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *ToggleSupergroupIsForumRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleSupergroupIsForum#161dfe11 as nil")
	}
	b.ObjStart()
	b.PutID("toggleSupergroupIsForum")
	b.Comma()
	b.FieldStart("supergroup_id")
	b.PutInt53(t.SupergroupID)
	b.Comma()
	b.FieldStart("is_forum")
	b.PutBool(t.IsForum)
	b.Comma()
	b.FieldStart("has_forum_tabs")
	b.PutBool(t.HasForumTabs)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (t *ToggleSupergroupIsForumRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleSupergroupIsForum#161dfe11 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("toggleSupergroupIsForum"); err != nil {
				return fmt.Errorf("unable to decode toggleSupergroupIsForum#161dfe11: %w", err)
			}
		case "supergroup_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode toggleSupergroupIsForum#161dfe11: field supergroup_id: %w", err)
			}
			t.SupergroupID = value
		case "is_forum":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode toggleSupergroupIsForum#161dfe11: field is_forum: %w", err)
			}
			t.IsForum = value
		case "has_forum_tabs":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode toggleSupergroupIsForum#161dfe11: field has_forum_tabs: %w", err)
			}
			t.HasForumTabs = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetSupergroupID returns value of SupergroupID field.
func (t *ToggleSupergroupIsForumRequest) GetSupergroupID() (value int64) {
	if t == nil {
		return
	}
	return t.SupergroupID
}

// GetIsForum returns value of IsForum field.
func (t *ToggleSupergroupIsForumRequest) GetIsForum() (value bool) {
	if t == nil {
		return
	}
	return t.IsForum
}

// GetHasForumTabs returns value of HasForumTabs field.
func (t *ToggleSupergroupIsForumRequest) GetHasForumTabs() (value bool) {
	if t == nil {
		return
	}
	return t.HasForumTabs
}

// ToggleSupergroupIsForum invokes method toggleSupergroupIsForum#161dfe11 returning error if any.
func (c *Client) ToggleSupergroupIsForum(ctx context.Context, request *ToggleSupergroupIsForumRequest) error {
	var ok Ok

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