//! Error types for the web module.

use thiserror::Error;

/// Result type for web operations.
pub type WebResult<T> = Result<T, WebError>;

/// Errors that can occur during web operations.
#[derive(Error, Debug)]
pub enum WebError {
    /// HTML parsing error
    #[error("HTML parse error: {0}")]
    HtmlParseError(String),

    /// Markdown processing error
    #[error("Markdown error: {0}")]
    MarkdownError(String),

    /// Invalid HTML structure
    #[error("Invalid HTML: {0}")]
    InvalidHtml(String),

    /// UTF-8 encoding error
    #[error("UTF-8 error: {0}")]
    Utf8Error(#[from] std::string::FromUtf8Error),

    /// IO error
    #[error("IO error: {0}")]
    IoError(#[from] std::io::Error),

    /// JSON serialization error
    #[error("JSON error: {0}")]
    JsonError(#[from] serde_json::error::Error),

    /// Generic error
    #[error("{0}")]
    Other(String),
}

impl WebError {
    /// Create a new HTML parse error.
    pub fn html_parse(msg: impl Into<String>) -> Self {
        WebError::HtmlParseError(msg.into())
    }

    /// Create a new markdown error.
    pub fn markdown(msg: impl Into<String>) -> Self {
        WebError::MarkdownError(msg.into())
    }

    /// Create a new invalid HTML error.
    pub fn invalid_html(msg: impl Into<String>) -> Self {
        WebError::InvalidHtml(msg.into())
    }
}
