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

// SetQuickReplyShortcutNameRequest represents TL type `setQuickReplyShortcutName#b20f471`.
type SetQuickReplyShortcutNameRequest struct {
	// Unique identifier of the quick reply shortcut
	ShortcutID int32
	// New name for the shortcut. Use checkQuickReplyShortcutName to check its validness
	Name string
}

// SetQuickReplyShortcutNameRequestTypeID is TL type id of SetQuickReplyShortcutNameRequest.
const SetQuickReplyShortcutNameRequestTypeID = 0xb20f471

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

func (s *SetQuickReplyShortcutNameRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.ShortcutID == 0) {
		return false
	}
	if !(s.Name == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetQuickReplyShortcutNameRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setQuickReplyShortcutName",
		ID:   SetQuickReplyShortcutNameRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ShortcutID",
			SchemaName: "shortcut_id",
		},
		{
			Name:       "Name",
			SchemaName: "name",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetQuickReplyShortcutNameRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setQuickReplyShortcutName#b20f471 as nil")
	}
	b.PutID(SetQuickReplyShortcutNameRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetQuickReplyShortcutNameRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setQuickReplyShortcutName#b20f471 as nil")
	}
	b.PutInt32(s.ShortcutID)
	b.PutString(s.Name)
	return nil
}

// Decode implements bin.Decoder.
func (s *SetQuickReplyShortcutNameRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setQuickReplyShortcutName#b20f471 to nil")
	}
	if err := b.ConsumeID(SetQuickReplyShortcutNameRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode setQuickReplyShortcutName#b20f471: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SetQuickReplyShortcutNameRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setQuickReplyShortcutName#b20f471 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode setQuickReplyShortcutName#b20f471: field shortcut_id: %w", err)
		}
		s.ShortcutID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode setQuickReplyShortcutName#b20f471: field name: %w", err)
		}
		s.Name = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetQuickReplyShortcutNameRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setQuickReplyShortcutName#b20f471 as nil")
	}
	b.ObjStart()
	b.PutID("setQuickReplyShortcutName")
	b.Comma()
	b.FieldStart("shortcut_id")
	b.PutInt32(s.ShortcutID)
	b.Comma()
	b.FieldStart("name")
	b.PutString(s.Name)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SetQuickReplyShortcutNameRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode setQuickReplyShortcutName#b20f471 to nil")
	}

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

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

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

// SetQuickReplyShortcutName invokes method setQuickReplyShortcutName#b20f471 returning error if any.
func (c *Client) SetQuickReplyShortcutName(ctx context.Context, request *SetQuickReplyShortcutNameRequest) error {
	var ok Ok

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