//! Error types for ext4-mkfs operations.

use thiserror::Error;

/// Result type for ext4-mkfs operations.
pub type Result<T> = std::result::Result<T, Error>;

/// Errors that can occur during ext4-mkfs operations.
#[derive(Debug, Error)]
pub enum Error {
    /// I/O error from block device operations
    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),

    /// lwext4 returned an error code
    #[error("lwext4 error: {0}")]
    Lwext4(i32),

    /// Invalid configuration
    #[error("Invalid configuration: {0}")]
    InvalidConfig(String),

    /// Block device is too small
    #[error("Block device too small: minimum {min} bytes, got {actual} bytes")]
    DeviceTooSmall { min: u64, actual: u64 },
}

impl Error {
    /// Create an error from an lwext4 error code.
    pub fn from_lwext4(code: i32) -> Self {
        Error::Lwext4(code)
    }
}
