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

// ToggleBotIsAddedToAttachmentMenuRequest represents TL type `toggleBotIsAddedToAttachmentMenu#8e59de9a`.
type ToggleBotIsAddedToAttachmentMenuRequest struct {
	// Bot's user identifier
	BotUserID int64
	// Pass true to add the bot to attachment menu; pass false to remove the bot from
	// attachment menu
	IsAdded bool
	// Pass true if the current user allowed the bot to send them messages. Ignored if
	// is_added is false
	AllowWriteAccess bool
}

// ToggleBotIsAddedToAttachmentMenuRequestTypeID is TL type id of ToggleBotIsAddedToAttachmentMenuRequest.
const ToggleBotIsAddedToAttachmentMenuRequestTypeID = 0x8e59de9a

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

func (t *ToggleBotIsAddedToAttachmentMenuRequest) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.BotUserID == 0) {
		return false
	}
	if !(t.IsAdded == false) {
		return false
	}
	if !(t.AllowWriteAccess == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *ToggleBotIsAddedToAttachmentMenuRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "toggleBotIsAddedToAttachmentMenu",
		ID:   ToggleBotIsAddedToAttachmentMenuRequestTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BotUserID",
			SchemaName: "bot_user_id",
		},
		{
			Name:       "IsAdded",
			SchemaName: "is_added",
		},
		{
			Name:       "AllowWriteAccess",
			SchemaName: "allow_write_access",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *ToggleBotIsAddedToAttachmentMenuRequest) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleBotIsAddedToAttachmentMenu#8e59de9a as nil")
	}
	b.PutID(ToggleBotIsAddedToAttachmentMenuRequestTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *ToggleBotIsAddedToAttachmentMenuRequest) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleBotIsAddedToAttachmentMenu#8e59de9a as nil")
	}
	b.PutInt53(t.BotUserID)
	b.PutBool(t.IsAdded)
	b.PutBool(t.AllowWriteAccess)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (t *ToggleBotIsAddedToAttachmentMenuRequest) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleBotIsAddedToAttachmentMenu#8e59de9a to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode toggleBotIsAddedToAttachmentMenu#8e59de9a: field bot_user_id: %w", err)
		}
		t.BotUserID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode toggleBotIsAddedToAttachmentMenu#8e59de9a: field is_added: %w", err)
		}
		t.IsAdded = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode toggleBotIsAddedToAttachmentMenu#8e59de9a: field allow_write_access: %w", err)
		}
		t.AllowWriteAccess = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *ToggleBotIsAddedToAttachmentMenuRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleBotIsAddedToAttachmentMenu#8e59de9a as nil")
	}
	b.ObjStart()
	b.PutID("toggleBotIsAddedToAttachmentMenu")
	b.Comma()
	b.FieldStart("bot_user_id")
	b.PutInt53(t.BotUserID)
	b.Comma()
	b.FieldStart("is_added")
	b.PutBool(t.IsAdded)
	b.Comma()
	b.FieldStart("allow_write_access")
	b.PutBool(t.AllowWriteAccess)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("toggleBotIsAddedToAttachmentMenu"); err != nil {
				return fmt.Errorf("unable to decode toggleBotIsAddedToAttachmentMenu#8e59de9a: %w", err)
			}
		case "bot_user_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode toggleBotIsAddedToAttachmentMenu#8e59de9a: field bot_user_id: %w", err)
			}
			t.BotUserID = value
		case "is_added":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode toggleBotIsAddedToAttachmentMenu#8e59de9a: field is_added: %w", err)
			}
			t.IsAdded = value
		case "allow_write_access":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode toggleBotIsAddedToAttachmentMenu#8e59de9a: field allow_write_access: %w", err)
			}
			t.AllowWriteAccess = value
		default:
			return b.Skip()
		}
		return nil
	})
}

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

// GetIsAdded returns value of IsAdded field.
func (t *ToggleBotIsAddedToAttachmentMenuRequest) GetIsAdded() (value bool) {
	if t == nil {
		return
	}
	return t.IsAdded
}

// GetAllowWriteAccess returns value of AllowWriteAccess field.
func (t *ToggleBotIsAddedToAttachmentMenuRequest) GetAllowWriteAccess() (value bool) {
	if t == nil {
		return
	}
	return t.AllowWriteAccess
}

// ToggleBotIsAddedToAttachmentMenu invokes method toggleBotIsAddedToAttachmentMenu#8e59de9a returning error if any.
func (c *Client) ToggleBotIsAddedToAttachmentMenu(ctx context.Context, request *ToggleBotIsAddedToAttachmentMenuRequest) error {
	var ok Ok

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