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

// ReorderQuickReplyShortcutsRequest represents TL type `reorderQuickReplyShortcuts#b04981c4`.
type ReorderQuickReplyShortcutsRequest struct {
	// The new order of quick reply shortcuts
	ShortcutIDs []int32
}

// ReorderQuickReplyShortcutsRequestTypeID is TL type id of ReorderQuickReplyShortcutsRequest.
const ReorderQuickReplyShortcutsRequestTypeID = 0xb04981c4

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

func (r *ReorderQuickReplyShortcutsRequest) Zero() bool {
	if r == nil {
		return true
	}
	if !(r.ShortcutIDs == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (r *ReorderQuickReplyShortcutsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "reorderQuickReplyShortcuts",
		ID:   ReorderQuickReplyShortcutsRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ShortcutIDs",
			SchemaName: "shortcut_ids",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *ReorderQuickReplyShortcutsRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode reorderQuickReplyShortcuts#b04981c4 as nil")
	}
	b.PutID(ReorderQuickReplyShortcutsRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *ReorderQuickReplyShortcutsRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode reorderQuickReplyShortcuts#b04981c4 as nil")
	}
	b.PutInt(len(r.ShortcutIDs))
	for _, v := range r.ShortcutIDs {
		b.PutInt32(v)
	}
	return nil
}

// Decode implements bin.Decoder.
func (r *ReorderQuickReplyShortcutsRequest) Decode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode reorderQuickReplyShortcuts#b04981c4 to nil")
	}
	if err := b.ConsumeID(ReorderQuickReplyShortcutsRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode reorderQuickReplyShortcuts#b04981c4: %w", err)
	}
	return r.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (r *ReorderQuickReplyShortcutsRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode reorderQuickReplyShortcuts#b04981c4 to nil")
	}
	{
		headerLen, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode reorderQuickReplyShortcuts#b04981c4: field shortcut_ids: %w", err)
		}

		if headerLen > 0 {
			r.ShortcutIDs = make([]int32, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode reorderQuickReplyShortcuts#b04981c4: field shortcut_ids: %w", err)
			}
			r.ShortcutIDs = append(r.ShortcutIDs, value)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (r *ReorderQuickReplyShortcutsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if r == nil {
		return fmt.Errorf("can't encode reorderQuickReplyShortcuts#b04981c4 as nil")
	}
	b.ObjStart()
	b.PutID("reorderQuickReplyShortcuts")
	b.Comma()
	b.FieldStart("shortcut_ids")
	b.ArrStart()
	for _, v := range r.ShortcutIDs {
		b.PutInt32(v)
		b.Comma()
	}
	b.StripComma()
	b.ArrEnd()
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (r *ReorderQuickReplyShortcutsRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if r == nil {
		return fmt.Errorf("can't decode reorderQuickReplyShortcuts#b04981c4 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("reorderQuickReplyShortcuts"); err != nil {
				return fmt.Errorf("unable to decode reorderQuickReplyShortcuts#b04981c4: %w", err)
			}
		case "shortcut_ids":
			if err := b.Arr(func(b tdjson.Decoder) error {
				value, err := b.Int32()
				if err != nil {
					return fmt.Errorf("unable to decode reorderQuickReplyShortcuts#b04981c4: field shortcut_ids: %w", err)
				}
				r.ShortcutIDs = append(r.ShortcutIDs, value)
				return nil
			}); err != nil {
				return fmt.Errorf("unable to decode reorderQuickReplyShortcuts#b04981c4: field shortcut_ids: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetShortcutIDs returns value of ShortcutIDs field.
func (r *ReorderQuickReplyShortcutsRequest) GetShortcutIDs() (value []int32) {
	if r == nil {
		return
	}
	return r.ShortcutIDs
}

// ReorderQuickReplyShortcuts invokes method reorderQuickReplyShortcuts#b04981c4 returning error if any.
func (c *Client) ReorderQuickReplyShortcuts(ctx context.Context, shortcutids []int32) error {
	var ok Ok

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