// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// BotsSetBotMenuButtonRequest represents TL type `bots.setBotMenuButton#4504d54f`.
// Sets the menu button action »¹ for a given user or for all users
//
// Links:
//  1. https://core.telegram.org/api/bots/menu
//
// See https://core.telegram.org/method/bots.setBotMenuButton for reference.
type BotsSetBotMenuButtonRequest struct {
	// User ID
	UserID InputUserClass
	// Bot menu button action
	Button BotMenuButtonClass
}

// BotsSetBotMenuButtonRequestTypeID is TL type id of BotsSetBotMenuButtonRequest.
const BotsSetBotMenuButtonRequestTypeID = 0x4504d54f

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

func (s *BotsSetBotMenuButtonRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.UserID == nil) {
		return false
	}
	if !(s.Button == nil) {
		return false
	}

	return true
}

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

// FillFrom fills BotsSetBotMenuButtonRequest from given interface.
func (s *BotsSetBotMenuButtonRequest) FillFrom(from interface {
	GetUserID() (value InputUserClass)
	GetButton() (value BotMenuButtonClass)
}) {
	s.UserID = from.GetUserID()
	s.Button = from.GetButton()
}

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

// TypeName returns name of type in TL schema.
func (*BotsSetBotMenuButtonRequest) TypeName() string {
	return "bots.setBotMenuButton"
}

// TypeInfo returns info about TL type.
func (s *BotsSetBotMenuButtonRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "bots.setBotMenuButton",
		ID:   BotsSetBotMenuButtonRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
		{
			Name:       "Button",
			SchemaName: "button",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *BotsSetBotMenuButtonRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode bots.setBotMenuButton#4504d54f as nil")
	}
	b.PutID(BotsSetBotMenuButtonRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *BotsSetBotMenuButtonRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode bots.setBotMenuButton#4504d54f as nil")
	}
	if s.UserID == nil {
		return fmt.Errorf("unable to encode bots.setBotMenuButton#4504d54f: field user_id is nil")
	}
	if err := s.UserID.Encode(b); err != nil {
		return fmt.Errorf("unable to encode bots.setBotMenuButton#4504d54f: field user_id: %w", err)
	}
	if s.Button == nil {
		return fmt.Errorf("unable to encode bots.setBotMenuButton#4504d54f: field button is nil")
	}
	if err := s.Button.Encode(b); err != nil {
		return fmt.Errorf("unable to encode bots.setBotMenuButton#4504d54f: field button: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *BotsSetBotMenuButtonRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode bots.setBotMenuButton#4504d54f to nil")
	}
	if err := b.ConsumeID(BotsSetBotMenuButtonRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode bots.setBotMenuButton#4504d54f: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *BotsSetBotMenuButtonRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode bots.setBotMenuButton#4504d54f to nil")
	}
	{
		value, err := DecodeInputUser(b)
		if err != nil {
			return fmt.Errorf("unable to decode bots.setBotMenuButton#4504d54f: field user_id: %w", err)
		}
		s.UserID = value
	}
	{
		value, err := DecodeBotMenuButton(b)
		if err != nil {
			return fmt.Errorf("unable to decode bots.setBotMenuButton#4504d54f: field button: %w", err)
		}
		s.Button = value
	}
	return nil
}

// GetUserID returns value of UserID field.
func (s *BotsSetBotMenuButtonRequest) GetUserID() (value InputUserClass) {
	if s == nil {
		return
	}
	return s.UserID
}

// GetButton returns value of Button field.
func (s *BotsSetBotMenuButtonRequest) GetButton() (value BotMenuButtonClass) {
	if s == nil {
		return
	}
	return s.Button
}

// BotsSetBotMenuButton invokes method bots.setBotMenuButton#4504d54f returning error if any.
// Sets the menu button action »¹ for a given user or for all users
//
// Links:
//  1. https://core.telegram.org/api/bots/menu
//
// Possible errors:
//
//	400 BUTTON_INVALID: The specified button is invalid.
//	400 BUTTON_TEXT_INVALID: The specified button text is invalid.
//	400 BUTTON_URL_INVALID: Button URL invalid.
//	400 USER_BOT_REQUIRED: This method can only be called by a bot.
//
// See https://core.telegram.org/method/bots.setBotMenuButton for reference.
func (c *Client) BotsSetBotMenuButton(ctx context.Context, request *BotsSetBotMenuButtonRequest) (bool, error) {
	var result BoolBox

	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return false, err
	}
	_, ok := result.Bool.(*BoolTrue)
	return ok, nil
}
