package chat

import (
	"log/slog"

	"git.sr.ht/~ashkeel/strimertul/database"
	"git.sr.ht/~ashkeel/strimertul/log"
)

// WriteMessageRequest is an RPC to send a chat message with extra options
type WriteMessageRequest struct {
	Message   string `json:"message" desc:"Chat message to send"`
	ReplyTo   string `json:"reply_to,omitempty" desc:"If specified, send as reply to a message ID"`
	WhisperTo string `json:"whisper_to,omitempty" desc:"If specified, send as whisper to user ID"`
	Announce  bool   `json:"announce" desc:"If true, send as announcement"`
}

func WriteMessage(db database.Database, logger *slog.Logger, m WriteMessageRequest) {
	err := db.PutJSON(WriteMessageRPC, m)
	if err != nil {
		logger.Error("Failed to write chat message", log.Error(err))
	}
}
