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

// ToggleBotUsernameIsActiveRequest represents TL type `toggleBotUsernameIsActive#79639409`.
type ToggleBotUsernameIsActiveRequest struct {
	// Identifier of the target bot
	BotUserID int64
	// The username to change
	Username string
	// Pass true to activate the username; pass false to disable it
	IsActive bool
}

// ToggleBotUsernameIsActiveRequestTypeID is TL type id of ToggleBotUsernameIsActiveRequest.
const ToggleBotUsernameIsActiveRequestTypeID = 0x79639409

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

func (t *ToggleBotUsernameIsActiveRequest) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.BotUserID == 0) {
		return false
	}
	if !(t.Username == "") {
		return false
	}
	if !(t.IsActive == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *ToggleBotUsernameIsActiveRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "toggleBotUsernameIsActive",
		ID:   ToggleBotUsernameIsActiveRequestTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BotUserID",
			SchemaName: "bot_user_id",
		},
		{
			Name:       "Username",
			SchemaName: "username",
		},
		{
			Name:       "IsActive",
			SchemaName: "is_active",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *ToggleBotUsernameIsActiveRequest) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleBotUsernameIsActive#79639409 as nil")
	}
	b.PutID(ToggleBotUsernameIsActiveRequestTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *ToggleBotUsernameIsActiveRequest) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleBotUsernameIsActive#79639409 as nil")
	}
	b.PutInt53(t.BotUserID)
	b.PutString(t.Username)
	b.PutBool(t.IsActive)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (t *ToggleBotUsernameIsActiveRequest) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleBotUsernameIsActive#79639409 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode toggleBotUsernameIsActive#79639409: field bot_user_id: %w", err)
		}
		t.BotUserID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode toggleBotUsernameIsActive#79639409: field username: %w", err)
		}
		t.Username = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode toggleBotUsernameIsActive#79639409: field is_active: %w", err)
		}
		t.IsActive = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *ToggleBotUsernameIsActiveRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleBotUsernameIsActive#79639409 as nil")
	}
	b.ObjStart()
	b.PutID("toggleBotUsernameIsActive")
	b.Comma()
	b.FieldStart("bot_user_id")
	b.PutInt53(t.BotUserID)
	b.Comma()
	b.FieldStart("username")
	b.PutString(t.Username)
	b.Comma()
	b.FieldStart("is_active")
	b.PutBool(t.IsActive)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("toggleBotUsernameIsActive"); err != nil {
				return fmt.Errorf("unable to decode toggleBotUsernameIsActive#79639409: %w", err)
			}
		case "bot_user_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode toggleBotUsernameIsActive#79639409: field bot_user_id: %w", err)
			}
			t.BotUserID = value
		case "username":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode toggleBotUsernameIsActive#79639409: field username: %w", err)
			}
			t.Username = value
		case "is_active":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode toggleBotUsernameIsActive#79639409: field is_active: %w", err)
			}
			t.IsActive = value
		default:
			return b.Skip()
		}
		return nil
	})
}

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

// GetUsername returns value of Username field.
func (t *ToggleBotUsernameIsActiveRequest) GetUsername() (value string) {
	if t == nil {
		return
	}
	return t.Username
}

// GetIsActive returns value of IsActive field.
func (t *ToggleBotUsernameIsActiveRequest) GetIsActive() (value bool) {
	if t == nil {
		return
	}
	return t.IsActive
}

// ToggleBotUsernameIsActive invokes method toggleBotUsernameIsActive#79639409 returning error if any.
func (c *Client) ToggleBotUsernameIsActive(ctx context.Context, request *ToggleBotUsernameIsActiveRequest) error {
	var ok Ok

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