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

// AddQuickReplyShortcutMessageRequest represents TL type `addQuickReplyShortcutMessage#3f188b2a`.
type AddQuickReplyShortcutMessageRequest struct {
	// Name of the target shortcut
	ShortcutName string
	// Identifier of a quick reply message in the same shortcut to be replied; pass 0 if none
	ReplyToMessageID int64
	// The content of the message to be added; inputMessagePoll, inputMessageForwarded and
	// inputMessageLocation with live_period aren't supported
	InputMessageContent InputMessageContentClass
}

// AddQuickReplyShortcutMessageRequestTypeID is TL type id of AddQuickReplyShortcutMessageRequest.
const AddQuickReplyShortcutMessageRequestTypeID = 0x3f188b2a

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

func (a *AddQuickReplyShortcutMessageRequest) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.ShortcutName == "") {
		return false
	}
	if !(a.ReplyToMessageID == 0) {
		return false
	}
	if !(a.InputMessageContent == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (a *AddQuickReplyShortcutMessageRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "addQuickReplyShortcutMessage",
		ID:   AddQuickReplyShortcutMessageRequestTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ShortcutName",
			SchemaName: "shortcut_name",
		},
		{
			Name:       "ReplyToMessageID",
			SchemaName: "reply_to_message_id",
		},
		{
			Name:       "InputMessageContent",
			SchemaName: "input_message_content",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *AddQuickReplyShortcutMessageRequest) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode addQuickReplyShortcutMessage#3f188b2a as nil")
	}
	b.PutID(AddQuickReplyShortcutMessageRequestTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AddQuickReplyShortcutMessageRequest) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode addQuickReplyShortcutMessage#3f188b2a as nil")
	}
	b.PutString(a.ShortcutName)
	b.PutInt53(a.ReplyToMessageID)
	if a.InputMessageContent == nil {
		return fmt.Errorf("unable to encode addQuickReplyShortcutMessage#3f188b2a: field input_message_content is nil")
	}
	if err := a.InputMessageContent.Encode(b); err != nil {
		return fmt.Errorf("unable to encode addQuickReplyShortcutMessage#3f188b2a: field input_message_content: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (a *AddQuickReplyShortcutMessageRequest) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode addQuickReplyShortcutMessage#3f188b2a to nil")
	}
	if err := b.ConsumeID(AddQuickReplyShortcutMessageRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode addQuickReplyShortcutMessage#3f188b2a: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *AddQuickReplyShortcutMessageRequest) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode addQuickReplyShortcutMessage#3f188b2a to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode addQuickReplyShortcutMessage#3f188b2a: field shortcut_name: %w", err)
		}
		a.ShortcutName = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode addQuickReplyShortcutMessage#3f188b2a: field reply_to_message_id: %w", err)
		}
		a.ReplyToMessageID = value
	}
	{
		value, err := DecodeInputMessageContent(b)
		if err != nil {
			return fmt.Errorf("unable to decode addQuickReplyShortcutMessage#3f188b2a: field input_message_content: %w", err)
		}
		a.InputMessageContent = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (a *AddQuickReplyShortcutMessageRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if a == nil {
		return fmt.Errorf("can't encode addQuickReplyShortcutMessage#3f188b2a as nil")
	}
	b.ObjStart()
	b.PutID("addQuickReplyShortcutMessage")
	b.Comma()
	b.FieldStart("shortcut_name")
	b.PutString(a.ShortcutName)
	b.Comma()
	b.FieldStart("reply_to_message_id")
	b.PutInt53(a.ReplyToMessageID)
	b.Comma()
	b.FieldStart("input_message_content")
	if a.InputMessageContent == nil {
		return fmt.Errorf("unable to encode addQuickReplyShortcutMessage#3f188b2a: field input_message_content is nil")
	}
	if err := a.InputMessageContent.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode addQuickReplyShortcutMessage#3f188b2a: field input_message_content: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (a *AddQuickReplyShortcutMessageRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if a == nil {
		return fmt.Errorf("can't decode addQuickReplyShortcutMessage#3f188b2a to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("addQuickReplyShortcutMessage"); err != nil {
				return fmt.Errorf("unable to decode addQuickReplyShortcutMessage#3f188b2a: %w", err)
			}
		case "shortcut_name":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode addQuickReplyShortcutMessage#3f188b2a: field shortcut_name: %w", err)
			}
			a.ShortcutName = value
		case "reply_to_message_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode addQuickReplyShortcutMessage#3f188b2a: field reply_to_message_id: %w", err)
			}
			a.ReplyToMessageID = value
		case "input_message_content":
			value, err := DecodeTDLibJSONInputMessageContent(b)
			if err != nil {
				return fmt.Errorf("unable to decode addQuickReplyShortcutMessage#3f188b2a: field input_message_content: %w", err)
			}
			a.InputMessageContent = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetShortcutName returns value of ShortcutName field.
func (a *AddQuickReplyShortcutMessageRequest) GetShortcutName() (value string) {
	if a == nil {
		return
	}
	return a.ShortcutName
}

// GetReplyToMessageID returns value of ReplyToMessageID field.
func (a *AddQuickReplyShortcutMessageRequest) GetReplyToMessageID() (value int64) {
	if a == nil {
		return
	}
	return a.ReplyToMessageID
}

// GetInputMessageContent returns value of InputMessageContent field.
func (a *AddQuickReplyShortcutMessageRequest) GetInputMessageContent() (value InputMessageContentClass) {
	if a == nil {
		return
	}
	return a.InputMessageContent
}

// AddQuickReplyShortcutMessage invokes method addQuickReplyShortcutMessage#3f188b2a returning error if any.
func (c *Client) AddQuickReplyShortcutMessage(ctx context.Context, request *AddQuickReplyShortcutMessageRequest) (*QuickReplyMessage, error) {
	var result QuickReplyMessage

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