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

// CanBotSendMessagesRequest represents TL type `canBotSendMessages#206d948c`.
type CanBotSendMessagesRequest struct {
	// Identifier of the target bot
	BotUserID int64
}

// CanBotSendMessagesRequestTypeID is TL type id of CanBotSendMessagesRequest.
const CanBotSendMessagesRequestTypeID = 0x206d948c

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

func (c *CanBotSendMessagesRequest) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.BotUserID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *CanBotSendMessagesRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "canBotSendMessages",
		ID:   CanBotSendMessagesRequestTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BotUserID",
			SchemaName: "bot_user_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *CanBotSendMessagesRequest) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canBotSendMessages#206d948c as nil")
	}
	b.PutID(CanBotSendMessagesRequestTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CanBotSendMessagesRequest) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canBotSendMessages#206d948c as nil")
	}
	b.PutInt53(c.BotUserID)
	return nil
}

// Decode implements bin.Decoder.
func (c *CanBotSendMessagesRequest) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canBotSendMessages#206d948c to nil")
	}
	if err := b.ConsumeID(CanBotSendMessagesRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode canBotSendMessages#206d948c: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CanBotSendMessagesRequest) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canBotSendMessages#206d948c to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode canBotSendMessages#206d948c: field bot_user_id: %w", err)
		}
		c.BotUserID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CanBotSendMessagesRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode canBotSendMessages#206d948c as nil")
	}
	b.ObjStart()
	b.PutID("canBotSendMessages")
	b.Comma()
	b.FieldStart("bot_user_id")
	b.PutInt53(c.BotUserID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CanBotSendMessagesRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode canBotSendMessages#206d948c to nil")
	}

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

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

// CanBotSendMessages invokes method canBotSendMessages#206d948c returning error if any.
func (c *Client) CanBotSendMessages(ctx context.Context, botuserid int64) error {
	var ok Ok

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