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

// MessagesCheckQuickReplyShortcutRequest represents TL type `messages.checkQuickReplyShortcut#f1d0fbd3`.
// Before offering the user the choice to add a message to a quick reply shortcut¹, to
// make sure that none of the limits specified here »² were reached.
//
// Links:
//  1. https://core.telegram.org/api/business#quick-reply-shortcuts
//  2. https://core.telegram.org/api/business#quick-reply-shortcuts
//
// See https://core.telegram.org/method/messages.checkQuickReplyShortcut for reference.
type MessagesCheckQuickReplyShortcutRequest struct {
	// Shorcut name (not ID!).
	Shortcut string
}

// MessagesCheckQuickReplyShortcutRequestTypeID is TL type id of MessagesCheckQuickReplyShortcutRequest.
const MessagesCheckQuickReplyShortcutRequestTypeID = 0xf1d0fbd3

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

func (c *MessagesCheckQuickReplyShortcutRequest) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.Shortcut == "") {
		return false
	}

	return true
}

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

// FillFrom fills MessagesCheckQuickReplyShortcutRequest from given interface.
func (c *MessagesCheckQuickReplyShortcutRequest) FillFrom(from interface {
	GetShortcut() (value string)
}) {
	c.Shortcut = from.GetShortcut()
}

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

// TypeName returns name of type in TL schema.
func (*MessagesCheckQuickReplyShortcutRequest) TypeName() string {
	return "messages.checkQuickReplyShortcut"
}

// TypeInfo returns info about TL type.
func (c *MessagesCheckQuickReplyShortcutRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.checkQuickReplyShortcut",
		ID:   MessagesCheckQuickReplyShortcutRequestTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Shortcut",
			SchemaName: "shortcut",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *MessagesCheckQuickReplyShortcutRequest) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode messages.checkQuickReplyShortcut#f1d0fbd3 as nil")
	}
	b.PutID(MessagesCheckQuickReplyShortcutRequestTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *MessagesCheckQuickReplyShortcutRequest) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode messages.checkQuickReplyShortcut#f1d0fbd3 as nil")
	}
	b.PutString(c.Shortcut)
	return nil
}

// Decode implements bin.Decoder.
func (c *MessagesCheckQuickReplyShortcutRequest) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode messages.checkQuickReplyShortcut#f1d0fbd3 to nil")
	}
	if err := b.ConsumeID(MessagesCheckQuickReplyShortcutRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.checkQuickReplyShortcut#f1d0fbd3: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *MessagesCheckQuickReplyShortcutRequest) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode messages.checkQuickReplyShortcut#f1d0fbd3 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messages.checkQuickReplyShortcut#f1d0fbd3: field shortcut: %w", err)
		}
		c.Shortcut = value
	}
	return nil
}

// GetShortcut returns value of Shortcut field.
func (c *MessagesCheckQuickReplyShortcutRequest) GetShortcut() (value string) {
	if c == nil {
		return
	}
	return c.Shortcut
}

// MessagesCheckQuickReplyShortcut invokes method messages.checkQuickReplyShortcut#f1d0fbd3 returning error if any.
// Before offering the user the choice to add a message to a quick reply shortcut¹, to
// make sure that none of the limits specified here »² were reached.
//
// Links:
//  1. https://core.telegram.org/api/business#quick-reply-shortcuts
//  2. https://core.telegram.org/api/business#quick-reply-shortcuts
//
// Possible errors:
//
//	403 PREMIUM_ACCOUNT_REQUIRED: A premium account is required to execute this action.
//
// See https://core.telegram.org/method/messages.checkQuickReplyShortcut for reference.
func (c *Client) MessagesCheckQuickReplyShortcut(ctx context.Context, shortcut string) (bool, error) {
	var result BoolBox

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