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

// MessagesEditQuickReplyShortcutRequest represents TL type `messages.editQuickReplyShortcut#5c003cef`.
// Rename a quick reply shortcut¹.
// This will emit an updateQuickReplies² update to other logged-in sessions.
//
// Links:
//  1. https://core.telegram.org/api/business#quick-reply-shortcuts
//  2. https://core.telegram.org/constructor/updateQuickReplies
//
// See https://core.telegram.org/method/messages.editQuickReplyShortcut for reference.
type MessagesEditQuickReplyShortcutRequest struct {
	// Shortcut ID¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/business#quick-reply-shortcuts
	ShortcutID int
	// New shortcut name.
	Shortcut string
}

// MessagesEditQuickReplyShortcutRequestTypeID is TL type id of MessagesEditQuickReplyShortcutRequest.
const MessagesEditQuickReplyShortcutRequestTypeID = 0x5c003cef

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

func (e *MessagesEditQuickReplyShortcutRequest) Zero() bool {
	if e == nil {
		return true
	}
	if !(e.ShortcutID == 0) {
		return false
	}
	if !(e.Shortcut == "") {
		return false
	}

	return true
}

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

// FillFrom fills MessagesEditQuickReplyShortcutRequest from given interface.
func (e *MessagesEditQuickReplyShortcutRequest) FillFrom(from interface {
	GetShortcutID() (value int)
	GetShortcut() (value string)
}) {
	e.ShortcutID = from.GetShortcutID()
	e.Shortcut = from.GetShortcut()
}

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

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

// TypeInfo returns info about TL type.
func (e *MessagesEditQuickReplyShortcutRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.editQuickReplyShortcut",
		ID:   MessagesEditQuickReplyShortcutRequestTypeID,
	}
	if e == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ShortcutID",
			SchemaName: "shortcut_id",
		},
		{
			Name:       "Shortcut",
			SchemaName: "shortcut",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (e *MessagesEditQuickReplyShortcutRequest) Encode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode messages.editQuickReplyShortcut#5c003cef as nil")
	}
	b.PutID(MessagesEditQuickReplyShortcutRequestTypeID)
	return e.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (e *MessagesEditQuickReplyShortcutRequest) EncodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode messages.editQuickReplyShortcut#5c003cef as nil")
	}
	b.PutInt(e.ShortcutID)
	b.PutString(e.Shortcut)
	return nil
}

// Decode implements bin.Decoder.
func (e *MessagesEditQuickReplyShortcutRequest) Decode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode messages.editQuickReplyShortcut#5c003cef to nil")
	}
	if err := b.ConsumeID(MessagesEditQuickReplyShortcutRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.editQuickReplyShortcut#5c003cef: %w", err)
	}
	return e.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (e *MessagesEditQuickReplyShortcutRequest) DecodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode messages.editQuickReplyShortcut#5c003cef to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messages.editQuickReplyShortcut#5c003cef: field shortcut_id: %w", err)
		}
		e.ShortcutID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messages.editQuickReplyShortcut#5c003cef: field shortcut: %w", err)
		}
		e.Shortcut = value
	}
	return nil
}

// GetShortcutID returns value of ShortcutID field.
func (e *MessagesEditQuickReplyShortcutRequest) GetShortcutID() (value int) {
	if e == nil {
		return
	}
	return e.ShortcutID
}

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

// MessagesEditQuickReplyShortcut invokes method messages.editQuickReplyShortcut#5c003cef returning error if any.
// Rename a quick reply shortcut¹.
// This will emit an updateQuickReplies² update to other logged-in sessions.
//
// Links:
//  1. https://core.telegram.org/api/business#quick-reply-shortcuts
//  2. https://core.telegram.org/constructor/updateQuickReplies
//
// Possible errors:
//
//	403 PREMIUM_ACCOUNT_REQUIRED: A premium account is required to execute this action.
//	400 SHORTCUT_INVALID: The specified shortcut is invalid.
//
// See https://core.telegram.org/method/messages.editQuickReplyShortcut for reference.
func (c *Client) MessagesEditQuickReplyShortcut(ctx context.Context, request *MessagesEditQuickReplyShortcutRequest) (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
}
