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

// MessagesSendQuickReplyMessagesRequest represents TL type `messages.sendQuickReplyMessages#6c750de1`.
// Send a quick reply shortcut »¹.
//
// Links:
//  1. https://core.telegram.org/api/business#quick-reply-shortcuts
//
// See https://core.telegram.org/method/messages.sendQuickReplyMessages for reference.
type MessagesSendQuickReplyMessagesRequest struct {
	// The peer where to send the shortcut (users only, for now).
	Peer InputPeerClass
	// The ID of the quick reply shortcut to send.
	ShortcutID int
	// Specify a subset of messages from the shortcut to send; if empty, defaults to all of
	// them.
	ID []int
	// Unique client IDs required to prevent message resending, one for each message we're
	// sending, may be empty (but not recommended).
	RandomID []int64
}

// MessagesSendQuickReplyMessagesRequestTypeID is TL type id of MessagesSendQuickReplyMessagesRequest.
const MessagesSendQuickReplyMessagesRequestTypeID = 0x6c750de1

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

func (s *MessagesSendQuickReplyMessagesRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Peer == nil) {
		return false
	}
	if !(s.ShortcutID == 0) {
		return false
	}
	if !(s.ID == nil) {
		return false
	}
	if !(s.RandomID == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesSendQuickReplyMessagesRequest from given interface.
func (s *MessagesSendQuickReplyMessagesRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetShortcutID() (value int)
	GetID() (value []int)
	GetRandomID() (value []int64)
}) {
	s.Peer = from.GetPeer()
	s.ShortcutID = from.GetShortcutID()
	s.ID = from.GetID()
	s.RandomID = from.GetRandomID()
}

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

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

// TypeInfo returns info about TL type.
func (s *MessagesSendQuickReplyMessagesRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.sendQuickReplyMessages",
		ID:   MessagesSendQuickReplyMessagesRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "ShortcutID",
			SchemaName: "shortcut_id",
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "RandomID",
			SchemaName: "random_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *MessagesSendQuickReplyMessagesRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode messages.sendQuickReplyMessages#6c750de1 as nil")
	}
	b.PutID(MessagesSendQuickReplyMessagesRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *MessagesSendQuickReplyMessagesRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode messages.sendQuickReplyMessages#6c750de1 as nil")
	}
	if s.Peer == nil {
		return fmt.Errorf("unable to encode messages.sendQuickReplyMessages#6c750de1: field peer is nil")
	}
	if err := s.Peer.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messages.sendQuickReplyMessages#6c750de1: field peer: %w", err)
	}
	b.PutInt(s.ShortcutID)
	b.PutVectorHeader(len(s.ID))
	for _, v := range s.ID {
		b.PutInt(v)
	}
	b.PutVectorHeader(len(s.RandomID))
	for _, v := range s.RandomID {
		b.PutLong(v)
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *MessagesSendQuickReplyMessagesRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode messages.sendQuickReplyMessages#6c750de1 to nil")
	}
	if err := b.ConsumeID(MessagesSendQuickReplyMessagesRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.sendQuickReplyMessages#6c750de1: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *MessagesSendQuickReplyMessagesRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode messages.sendQuickReplyMessages#6c750de1 to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode messages.sendQuickReplyMessages#6c750de1: field peer: %w", err)
		}
		s.Peer = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messages.sendQuickReplyMessages#6c750de1: field shortcut_id: %w", err)
		}
		s.ShortcutID = value
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode messages.sendQuickReplyMessages#6c750de1: field id: %w", err)
		}

		if headerLen > 0 {
			s.ID = make([]int, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := b.Int()
			if err != nil {
				return fmt.Errorf("unable to decode messages.sendQuickReplyMessages#6c750de1: field id: %w", err)
			}
			s.ID = append(s.ID, value)
		}
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode messages.sendQuickReplyMessages#6c750de1: field random_id: %w", err)
		}

		if headerLen > 0 {
			s.RandomID = make([]int64, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := b.Long()
			if err != nil {
				return fmt.Errorf("unable to decode messages.sendQuickReplyMessages#6c750de1: field random_id: %w", err)
			}
			s.RandomID = append(s.RandomID, value)
		}
	}
	return nil
}

// GetPeer returns value of Peer field.
func (s *MessagesSendQuickReplyMessagesRequest) GetPeer() (value InputPeerClass) {
	if s == nil {
		return
	}
	return s.Peer
}

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

// GetID returns value of ID field.
func (s *MessagesSendQuickReplyMessagesRequest) GetID() (value []int) {
	if s == nil {
		return
	}
	return s.ID
}

// GetRandomID returns value of RandomID field.
func (s *MessagesSendQuickReplyMessagesRequest) GetRandomID() (value []int64) {
	if s == nil {
		return
	}
	return s.RandomID
}

// MessagesSendQuickReplyMessages invokes method messages.sendQuickReplyMessages#6c750de1 returning error if any.
// Send a quick reply shortcut »¹.
//
// Links:
//  1. https://core.telegram.org/api/business#quick-reply-shortcuts
//
// Possible errors:
//
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//	403 PREMIUM_ACCOUNT_REQUIRED: A premium account is required to execute this action.
//
// See https://core.telegram.org/method/messages.sendQuickReplyMessages for reference.
func (c *Client) MessagesSendQuickReplyMessages(ctx context.Context, request *MessagesSendQuickReplyMessagesRequest) (UpdatesClass, error) {
	var result UpdatesBox

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