//! Chat domain error types and result alias used across HTTP [`openapi.yaml`](../../../openapi.yaml) `/chat/*` handlers.

use thiserror::Error;

/// Result alias for chat operations that may fail with [`ChatError`].
pub type ChatResult<T> = Result<T, ChatError>;

/// Domain errors surfaced by [`crate::ChatApp`] and repository layers.
///
/// HTTP adapters map variants to status codes and registry codes (for example `CHAT_NOT_FOUND`).
#[derive(Debug, Error)]
pub enum ChatError {
    #[error("chat authentication required")]
    Unauthorized,
    #[error("{0}")]
    Forbidden(String),
    #[error("{0}")]
    NotFound(String),
    #[error("{0}")]
    Conflict(String),
    #[error("{0}")]
    Validation(String),
    #[error("{0}")]
    Unavailable(String),
    #[error("{0}")]
    Unsupported(String),
    #[error("{0}")]
    Internal(String),
}

impl From<sqlx::Error> for ChatError {
    fn from(value: sqlx::Error) -> Self {
        Self::Internal(value.to_string())
    }
}
