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

// SendQuickReplyShortcutMessagesRequest represents TL type `sendQuickReplyShortcutMessages#dd5169d`.
type SendQuickReplyShortcutMessagesRequest struct {
	// Identifier of the chat to which to send messages. The chat must be a private chat with
	// a regular user
	ChatID int64
	// Unique identifier of the quick reply shortcut
	ShortcutID int32
	// Non-persistent identifier, which will be returned back in messageSendingStatePending
	// object and can be used to match sent messages and corresponding updateNewMessage
	// updates
	SendingID int32
}

// SendQuickReplyShortcutMessagesRequestTypeID is TL type id of SendQuickReplyShortcutMessagesRequest.
const SendQuickReplyShortcutMessagesRequestTypeID = 0xdd5169d

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

func (s *SendQuickReplyShortcutMessagesRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.ChatID == 0) {
		return false
	}
	if !(s.ShortcutID == 0) {
		return false
	}
	if !(s.SendingID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SendQuickReplyShortcutMessagesRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "sendQuickReplyShortcutMessages",
		ID:   SendQuickReplyShortcutMessagesRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "ShortcutID",
			SchemaName: "shortcut_id",
		},
		{
			Name:       "SendingID",
			SchemaName: "sending_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SendQuickReplyShortcutMessagesRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode sendQuickReplyShortcutMessages#dd5169d as nil")
	}
	b.PutID(SendQuickReplyShortcutMessagesRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SendQuickReplyShortcutMessagesRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode sendQuickReplyShortcutMessages#dd5169d as nil")
	}
	b.PutInt53(s.ChatID)
	b.PutInt32(s.ShortcutID)
	b.PutInt32(s.SendingID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *SendQuickReplyShortcutMessagesRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode sendQuickReplyShortcutMessages#dd5169d to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode sendQuickReplyShortcutMessages#dd5169d: field chat_id: %w", err)
		}
		s.ChatID = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode sendQuickReplyShortcutMessages#dd5169d: field shortcut_id: %w", err)
		}
		s.ShortcutID = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode sendQuickReplyShortcutMessages#dd5169d: field sending_id: %w", err)
		}
		s.SendingID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SendQuickReplyShortcutMessagesRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode sendQuickReplyShortcutMessages#dd5169d as nil")
	}
	b.ObjStart()
	b.PutID("sendQuickReplyShortcutMessages")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(s.ChatID)
	b.Comma()
	b.FieldStart("shortcut_id")
	b.PutInt32(s.ShortcutID)
	b.Comma()
	b.FieldStart("sending_id")
	b.PutInt32(s.SendingID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetChatID returns value of ChatID field.
func (s *SendQuickReplyShortcutMessagesRequest) GetChatID() (value int64) {
	if s == nil {
		return
	}
	return s.ChatID
}

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

// GetSendingID returns value of SendingID field.
func (s *SendQuickReplyShortcutMessagesRequest) GetSendingID() (value int32) {
	if s == nil {
		return
	}
	return s.SendingID
}

// SendQuickReplyShortcutMessages invokes method sendQuickReplyShortcutMessages#dd5169d returning error if any.
func (c *Client) SendQuickReplyShortcutMessages(ctx context.Context, request *SendQuickReplyShortcutMessagesRequest) (*Messages, error) {
	var result Messages

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