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

// DeleteQuickReplyShortcutRequest represents TL type `deleteQuickReplyShortcut#f1486c16`.
type DeleteQuickReplyShortcutRequest struct {
	// Unique identifier of the quick reply shortcut
	ShortcutID int32
}

// DeleteQuickReplyShortcutRequestTypeID is TL type id of DeleteQuickReplyShortcutRequest.
const DeleteQuickReplyShortcutRequestTypeID = 0xf1486c16

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

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (d *DeleteQuickReplyShortcutRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteQuickReplyShortcut#f1486c16 as nil")
	}
	b.PutID(DeleteQuickReplyShortcutRequestTypeID)
	return d.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (d *DeleteQuickReplyShortcutRequest) EncodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteQuickReplyShortcut#f1486c16 as nil")
	}
	b.PutInt32(d.ShortcutID)
	return nil
}

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

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

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (d *DeleteQuickReplyShortcutRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteQuickReplyShortcut#f1486c16 as nil")
	}
	b.ObjStart()
	b.PutID("deleteQuickReplyShortcut")
	b.Comma()
	b.FieldStart("shortcut_id")
	b.PutInt32(d.ShortcutID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

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

// DeleteQuickReplyShortcut invokes method deleteQuickReplyShortcut#f1486c16 returning error if any.
func (c *Client) DeleteQuickReplyShortcut(ctx context.Context, shortcutid int32) error {
	var ok Ok

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