// Code generated by gotdgen, DO NOT EDIT.

package tdapi

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

// DeleteQuickReplyShortcutMessagesRequest represents TL type `deleteQuickReplyShortcutMessages#e859fcbb`.
type DeleteQuickReplyShortcutMessagesRequest struct {
	// Unique identifier of the quick reply shortcut to which the messages belong
	ShortcutID int32
	// Unique identifiers of the messages
	MessageIDs []int64
}

// DeleteQuickReplyShortcutMessagesRequestTypeID is TL type id of DeleteQuickReplyShortcutMessagesRequest.
const DeleteQuickReplyShortcutMessagesRequestTypeID = 0xe859fcbb

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

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

	return true
}

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

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

// TypeName returns name of type in TL schema.
func (*DeleteQuickReplyShortcutMessagesRequest) TypeName() string {
	return "deleteQuickReplyShortcutMessages"
}

// TypeInfo returns info about TL type.
func (d *DeleteQuickReplyShortcutMessagesRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "deleteQuickReplyShortcutMessages",
		ID:   DeleteQuickReplyShortcutMessagesRequestTypeID,
	}
	if d == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ShortcutID",
			SchemaName: "shortcut_id",
		},
		{
			Name:       "MessageIDs",
			SchemaName: "message_ids",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (d *DeleteQuickReplyShortcutMessagesRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteQuickReplyShortcutMessages#e859fcbb as nil")
	}
	b.PutID(DeleteQuickReplyShortcutMessagesRequestTypeID)
	return d.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (d *DeleteQuickReplyShortcutMessagesRequest) EncodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteQuickReplyShortcutMessages#e859fcbb as nil")
	}
	b.PutInt32(d.ShortcutID)
	b.PutInt(len(d.MessageIDs))
	for _, v := range d.MessageIDs {
		b.PutInt53(v)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (d *DeleteQuickReplyShortcutMessagesRequest) DecodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteQuickReplyShortcutMessages#e859fcbb to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode deleteQuickReplyShortcutMessages#e859fcbb: field shortcut_id: %w", err)
		}
		d.ShortcutID = value
	}
	{
		headerLen, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode deleteQuickReplyShortcutMessages#e859fcbb: field message_ids: %w", err)
		}

		if headerLen > 0 {
			d.MessageIDs = make([]int64, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode deleteQuickReplyShortcutMessages#e859fcbb: field message_ids: %w", err)
			}
			d.MessageIDs = append(d.MessageIDs, value)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (d *DeleteQuickReplyShortcutMessagesRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteQuickReplyShortcutMessages#e859fcbb as nil")
	}
	b.ObjStart()
	b.PutID("deleteQuickReplyShortcutMessages")
	b.Comma()
	b.FieldStart("shortcut_id")
	b.PutInt32(d.ShortcutID)
	b.Comma()
	b.FieldStart("message_ids")
	b.ArrStart()
	for _, v := range d.MessageIDs {
		b.PutInt53(v)
		b.Comma()
	}
	b.StripComma()
	b.ArrEnd()
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (d *DeleteQuickReplyShortcutMessagesRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteQuickReplyShortcutMessages#e859fcbb to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("deleteQuickReplyShortcutMessages"); err != nil {
				return fmt.Errorf("unable to decode deleteQuickReplyShortcutMessages#e859fcbb: %w", err)
			}
		case "shortcut_id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode deleteQuickReplyShortcutMessages#e859fcbb: field shortcut_id: %w", err)
			}
			d.ShortcutID = value
		case "message_ids":
			if err := b.Arr(func(b tdjson.Decoder) error {
				value, err := b.Int53()
				if err != nil {
					return fmt.Errorf("unable to decode deleteQuickReplyShortcutMessages#e859fcbb: field message_ids: %w", err)
				}
				d.MessageIDs = append(d.MessageIDs, value)
				return nil
			}); err != nil {
				return fmt.Errorf("unable to decode deleteQuickReplyShortcutMessages#e859fcbb: field message_ids: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

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

// GetMessageIDs returns value of MessageIDs field.
func (d *DeleteQuickReplyShortcutMessagesRequest) GetMessageIDs() (value []int64) {
	if d == nil {
		return
	}
	return d.MessageIDs
}

// DeleteQuickReplyShortcutMessages invokes method deleteQuickReplyShortcutMessages#e859fcbb returning error if any.
func (c *Client) DeleteQuickReplyShortcutMessages(ctx context.Context, request *DeleteQuickReplyShortcutMessagesRequest) error {
	var ok Ok

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