/// Errors that can occur when fetching or parsing NEMWeb data.
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// HTTP request failed (network error, timeout, non-2xx status).
    #[error("HTTP request failed: {0}")]
    Http(#[from] reqwest::Error),

    /// Failed to read or extract the ZIP archive.
    #[error("ZIP extraction failed: {0}")]
    Zip(#[from] zip::result::ZipError),

    /// I/O error while reading extracted file contents.
    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),

    /// Failed to compile a regex pattern (internal bug).
    #[error("Regex error: {0}")]
    Regex(#[from] regex::Error),

    /// No matching data file found in the AEMO directory listing.
    #[error("{0}")]
    NotFound(String),

    /// Invalid date format. Expected `"YYYY-MM-DD"`.
    #[error("invalid date \"{value}\": expected format YYYY-MM-DD")]
    InvalidDate {
        /// The offending date string the user passed.
        value: String,
    },
}

/// Result type alias for [`Error`].
pub type Result<T> = std::result::Result<T, Error>;
