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

// CheckQuickReplyShortcutNameRequest represents TL type `checkQuickReplyShortcutName#7d3dd129`.
type CheckQuickReplyShortcutNameRequest struct {
	// The name of the shortcut; 1-32 characters
	Name string
}

// CheckQuickReplyShortcutNameRequestTypeID is TL type id of CheckQuickReplyShortcutNameRequest.
const CheckQuickReplyShortcutNameRequestTypeID = 0x7d3dd129

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

func (c *CheckQuickReplyShortcutNameRequest) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.Name == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *CheckQuickReplyShortcutNameRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "checkQuickReplyShortcutName",
		ID:   CheckQuickReplyShortcutNameRequestTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Name",
			SchemaName: "name",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *CheckQuickReplyShortcutNameRequest) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode checkQuickReplyShortcutName#7d3dd129 as nil")
	}
	b.PutID(CheckQuickReplyShortcutNameRequestTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CheckQuickReplyShortcutNameRequest) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode checkQuickReplyShortcutName#7d3dd129 as nil")
	}
	b.PutString(c.Name)
	return nil
}

// Decode implements bin.Decoder.
func (c *CheckQuickReplyShortcutNameRequest) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode checkQuickReplyShortcutName#7d3dd129 to nil")
	}
	if err := b.ConsumeID(CheckQuickReplyShortcutNameRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode checkQuickReplyShortcutName#7d3dd129: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CheckQuickReplyShortcutNameRequest) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode checkQuickReplyShortcutName#7d3dd129 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode checkQuickReplyShortcutName#7d3dd129: field name: %w", err)
		}
		c.Name = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CheckQuickReplyShortcutNameRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode checkQuickReplyShortcutName#7d3dd129 as nil")
	}
	b.ObjStart()
	b.PutID("checkQuickReplyShortcutName")
	b.Comma()
	b.FieldStart("name")
	b.PutString(c.Name)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CheckQuickReplyShortcutNameRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode checkQuickReplyShortcutName#7d3dd129 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("checkQuickReplyShortcutName"); err != nil {
				return fmt.Errorf("unable to decode checkQuickReplyShortcutName#7d3dd129: %w", err)
			}
		case "name":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode checkQuickReplyShortcutName#7d3dd129: field name: %w", err)
			}
			c.Name = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetName returns value of Name field.
func (c *CheckQuickReplyShortcutNameRequest) GetName() (value string) {
	if c == nil {
		return
	}
	return c.Name
}

// CheckQuickReplyShortcutName invokes method checkQuickReplyShortcutName#7d3dd129 returning error if any.
func (c *Client) CheckQuickReplyShortcutName(ctx context.Context, name string) error {
	var ok Ok

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