//! Error types for archmeld operations.

use std::path::PathBuf;

/// All errors that can occur during archive operations.
#[derive(Debug, thiserror::Error)]
#[allow(dead_code)]
pub enum Error {
    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),

    #[error("ZIP error: {0}")]
    Zip(#[from] zip::result::ZipError),

    #[error("7-Zip error: {0}")]
    SevenZip(String),

    #[error("LZMA error: {0}")]
    Lzma(#[from] lzma_rs::error::Error),

    #[error("LZ4 decompression error: {0}")]
    Lz4(String),

    #[error("Unsupported archive format: {0}")]
    UnsupportedFormat(String),

    #[error("Invalid archive: {0}")]
    InvalidArchive(String),

    #[error("File too large: {size} bytes exceeds limit of {limit} bytes")]
    FileTooLarge { size: u64, limit: u64 },

    #[error("Total extraction size exceeds limit of {limit} bytes")]
    TotalSizeLimitExceeded { limit: u64 },

    #[error("Path traversal detected in archive entry: {0}")]
    PathTraversal(String),

    #[error("File not found: {}", .0.display())]
    FileNotFound(PathBuf),

    #[error("Invalid gzip header: {0}")]
    InvalidGzipHeader(String),

    #[error("Invalid StuffIt archive: {0}")]
    InvalidStuffIt(String),

    #[error("Invalid Compact Pro archive: {0}")]
    InvalidCompactPro(String),

    #[error("Checksum mismatch: expected {expected}, got {actual}")]
    ChecksumMismatch { expected: String, actual: String },

    #[error("Encrypted archive entries are not supported")]
    EncryptedNotSupported,

    #[error("Archive bomb detected: compression ratio {ratio:.0}:1 exceeds limit of {limit:.0}:1")]
    CompressionBomb { ratio: f64, limit: f64 },

    #[error("Too many entries: {count} exceeds limit of {limit}")]
    TooManyEntries { count: usize, limit: usize },

    #[error("RAR error: {0}")]
    Rar(String),

    #[error("CAB error: {0}")]
    Cab(String),

    #[error("AR error: {0}")]
    Ar(String),

    #[error("Brotli decompression error: {0}")]
    Brotli(String),

    #[error("Snappy decompression error: {0}")]
    Snappy(String),

    #[error("Symlink rejected in archive: {0}")]
    SymlinkRejected(String),
}

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