package errors

import "github.com/hhs/camtalk/internal/models"

// 错误码常量，与 docs/03-接口文档.md 保持一致。
const (
	CodeInvalidMessage  = "INVALID_MESSAGE"
	CodeSessionNotFound = "SESSION_NOT_FOUND"
	CodeRateLimited     = "RATE_LIMITED"
	CodeImageTooLarge   = "IMAGE_TOO_LARGE"
	CodeAudioTooShort   = "AUDIO_TOO_SHORT"
	CodeLLMTimeout      = "LLM_TIMEOUT"
	CodeLLMError        = "LLM_ERROR"
	CodeSTTError        = "STT_ERROR"
	CodeTTSError        = "TTS_ERROR"
	CodeInternalError   = "INTERNAL_ERROR"

	// 认证相关错误码
	CodeUsernameTaken      = "USERNAME_TAKEN"
	CodeInvalidCredentials = "INVALID_CREDENTIALS"
	CodeInvalidToken       = "INVALID_TOKEN"
	CodeInvalidInput       = "INVALID_INPUT"
)

// Sender 定义发送 WS 错误消息的接口，便于测试 mock。
type Sender interface {
	SendError(code, requestID, message string)
}

// SendWSError 向客户端发送 error 消息。
// sender 是一个具有 sendJSON 方法的对象，这里用接口抽象。
func SendWSError(sender interface{ SendJSON(v any) error }, code, requestID string, err error) {
	_ = sender.SendJSON(models.WsError{
		Type:      "error",
		Code:      code,
		RequestID: requestID,
		Message:   err.Error(),
	})
}
