use std::path::PathBuf;

#[derive(Debug, thiserror::Error)]
pub enum ZipError {
    #[error("invalid ZIP: {0}")]
    Invalid(&'static str),
    #[error("unsupported ZIP feature: {0}")]
    Unsupported(&'static str),
    #[error("entry name is not valid UTF-8")]
    InvalidUtf8,
    #[error("unsafe extraction path: {0}")]
    UnsafePath(String),
    #[error("CRC mismatch for {name}: expected {expected:08x}, got {actual:08x}")]
    CrcMismatch {
        name: String,
        expected: u32,
        actual: u32,
    },
    #[error("size mismatch for {name}: expected {expected}, got {actual}")]
    SizeMismatch {
        name: String,
        expected: u64,
        actual: u64,
    },
    #[error("entry would overwrite extraction root: {0}")]
    RootOverwrite(PathBuf),
    #[error("unknown variant {variant:?} for {function}")]
    UnknownVariant {
        function: &'static str,
        variant: String,
    },
    #[error("HTTP error: {0}")]
    Http(String),
    #[error(transparent)]
    Io(#[from] std::io::Error),
    #[error(transparent)]
    Json(#[from] serde_json::Error),
}

pub type Result<T> = std::result::Result<T, ZipError>;
