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

// ToggleBotCanManageEmojiStatusRequest represents TL type `toggleBotCanManageEmojiStatus#251a881a`.
type ToggleBotCanManageEmojiStatusRequest struct {
	// User identifier of the bot
	BotUserID int64
	// Pass true if the bot is allowed to change emoji status of the user; pass false
	// otherwise
	CanManageEmojiStatus bool
}

// ToggleBotCanManageEmojiStatusRequestTypeID is TL type id of ToggleBotCanManageEmojiStatusRequest.
const ToggleBotCanManageEmojiStatusRequestTypeID = 0x251a881a

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

func (t *ToggleBotCanManageEmojiStatusRequest) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.BotUserID == 0) {
		return false
	}
	if !(t.CanManageEmojiStatus == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *ToggleBotCanManageEmojiStatusRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "toggleBotCanManageEmojiStatus",
		ID:   ToggleBotCanManageEmojiStatusRequestTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BotUserID",
			SchemaName: "bot_user_id",
		},
		{
			Name:       "CanManageEmojiStatus",
			SchemaName: "can_manage_emoji_status",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *ToggleBotCanManageEmojiStatusRequest) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleBotCanManageEmojiStatus#251a881a as nil")
	}
	b.PutID(ToggleBotCanManageEmojiStatusRequestTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *ToggleBotCanManageEmojiStatusRequest) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleBotCanManageEmojiStatus#251a881a as nil")
	}
	b.PutInt53(t.BotUserID)
	b.PutBool(t.CanManageEmojiStatus)
	return nil
}

// Decode implements bin.Decoder.
func (t *ToggleBotCanManageEmojiStatusRequest) Decode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleBotCanManageEmojiStatus#251a881a to nil")
	}
	if err := b.ConsumeID(ToggleBotCanManageEmojiStatusRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode toggleBotCanManageEmojiStatus#251a881a: %w", err)
	}
	return t.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (t *ToggleBotCanManageEmojiStatusRequest) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleBotCanManageEmojiStatus#251a881a to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode toggleBotCanManageEmojiStatus#251a881a: field bot_user_id: %w", err)
		}
		t.BotUserID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode toggleBotCanManageEmojiStatus#251a881a: field can_manage_emoji_status: %w", err)
		}
		t.CanManageEmojiStatus = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *ToggleBotCanManageEmojiStatusRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleBotCanManageEmojiStatus#251a881a as nil")
	}
	b.ObjStart()
	b.PutID("toggleBotCanManageEmojiStatus")
	b.Comma()
	b.FieldStart("bot_user_id")
	b.PutInt53(t.BotUserID)
	b.Comma()
	b.FieldStart("can_manage_emoji_status")
	b.PutBool(t.CanManageEmojiStatus)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (t *ToggleBotCanManageEmojiStatusRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleBotCanManageEmojiStatus#251a881a to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("toggleBotCanManageEmojiStatus"); err != nil {
				return fmt.Errorf("unable to decode toggleBotCanManageEmojiStatus#251a881a: %w", err)
			}
		case "bot_user_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode toggleBotCanManageEmojiStatus#251a881a: field bot_user_id: %w", err)
			}
			t.BotUserID = value
		case "can_manage_emoji_status":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode toggleBotCanManageEmojiStatus#251a881a: field can_manage_emoji_status: %w", err)
			}
			t.CanManageEmojiStatus = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetBotUserID returns value of BotUserID field.
func (t *ToggleBotCanManageEmojiStatusRequest) GetBotUserID() (value int64) {
	if t == nil {
		return
	}
	return t.BotUserID
}

// GetCanManageEmojiStatus returns value of CanManageEmojiStatus field.
func (t *ToggleBotCanManageEmojiStatusRequest) GetCanManageEmojiStatus() (value bool) {
	if t == nil {
		return
	}
	return t.CanManageEmojiStatus
}

// ToggleBotCanManageEmojiStatus invokes method toggleBotCanManageEmojiStatus#251a881a returning error if any.
func (c *Client) ToggleBotCanManageEmojiStatus(ctx context.Context, request *ToggleBotCanManageEmojiStatusRequest) error {
	var ok Ok

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