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

// MessagesDeleteQuickReplyMessagesRequest represents TL type `messages.deleteQuickReplyMessages#e105e910`.
// Delete one or more messages from a quick reply shortcut¹. This will also emit an
// updateDeleteQuickReplyMessages² update.
//
// Links:
//  1. https://core.telegram.org/api/business#quick-reply-shortcuts
//  2. https://core.telegram.org/constructor/updateDeleteQuickReplyMessages
//
// See https://core.telegram.org/method/messages.deleteQuickReplyMessages for reference.
type MessagesDeleteQuickReplyMessagesRequest struct {
	// Shortcut ID¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/business#quick-reply-shortcuts
	ShortcutID int
	// IDs of shortcut messages to delete.
	ID []int
}

// MessagesDeleteQuickReplyMessagesRequestTypeID is TL type id of MessagesDeleteQuickReplyMessagesRequest.
const MessagesDeleteQuickReplyMessagesRequestTypeID = 0xe105e910

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

func (d *MessagesDeleteQuickReplyMessagesRequest) Zero() bool {
	if d == nil {
		return true
	}
	if !(d.ShortcutID == 0) {
		return false
	}
	if !(d.ID == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesDeleteQuickReplyMessagesRequest from given interface.
func (d *MessagesDeleteQuickReplyMessagesRequest) FillFrom(from interface {
	GetShortcutID() (value int)
	GetID() (value []int)
}) {
	d.ShortcutID = from.GetShortcutID()
	d.ID = from.GetID()
}

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

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

// TypeInfo returns info about TL type.
func (d *MessagesDeleteQuickReplyMessagesRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.deleteQuickReplyMessages",
		ID:   MessagesDeleteQuickReplyMessagesRequestTypeID,
	}
	if d == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ShortcutID",
			SchemaName: "shortcut_id",
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (d *MessagesDeleteQuickReplyMessagesRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode messages.deleteQuickReplyMessages#e105e910 as nil")
	}
	b.PutID(MessagesDeleteQuickReplyMessagesRequestTypeID)
	return d.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (d *MessagesDeleteQuickReplyMessagesRequest) EncodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode messages.deleteQuickReplyMessages#e105e910 as nil")
	}
	b.PutInt(d.ShortcutID)
	b.PutVectorHeader(len(d.ID))
	for _, v := range d.ID {
		b.PutInt(v)
	}
	return nil
}

// Decode implements bin.Decoder.
func (d *MessagesDeleteQuickReplyMessagesRequest) Decode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode messages.deleteQuickReplyMessages#e105e910 to nil")
	}
	if err := b.ConsumeID(MessagesDeleteQuickReplyMessagesRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.deleteQuickReplyMessages#e105e910: %w", err)
	}
	return d.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (d *MessagesDeleteQuickReplyMessagesRequest) DecodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode messages.deleteQuickReplyMessages#e105e910 to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messages.deleteQuickReplyMessages#e105e910: field shortcut_id: %w", err)
		}
		d.ShortcutID = value
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode messages.deleteQuickReplyMessages#e105e910: field id: %w", err)
		}

		if headerLen > 0 {
			d.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.deleteQuickReplyMessages#e105e910: field id: %w", err)
			}
			d.ID = append(d.ID, value)
		}
	}
	return nil
}

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

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

// MessagesDeleteQuickReplyMessages invokes method messages.deleteQuickReplyMessages#e105e910 returning error if any.
// Delete one or more messages from a quick reply shortcut¹. This will also emit an
// updateDeleteQuickReplyMessages² update.
//
// Links:
//  1. https://core.telegram.org/api/business#quick-reply-shortcuts
//  2. https://core.telegram.org/constructor/updateDeleteQuickReplyMessages
//
// Possible errors:
//
//	400 SHORTCUT_INVALID: The specified shortcut is invalid.
//
// See https://core.telegram.org/method/messages.deleteQuickReplyMessages for reference.
func (c *Client) MessagesDeleteQuickReplyMessages(ctx context.Context, request *MessagesDeleteQuickReplyMessagesRequest) (UpdatesClass, error) {
	var result UpdatesBox

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