use thiserror::Error;

/// Core error types used across services for consistent error handling.
///
/// This enum centralizes errors from database, I/O, validation, and other operations.
/// It implements Error and Debug for propagation and logging. Use this for all service-level errors.
///
/// # Variants
///
/// * `Database(rusqlite::Error)` - Wraps SQLite errors from queries or transactions.
/// * `Io(std::io::Error)` - Wraps I/O errors from file operations or streams.
/// * `ItemNotFound(i64)` - Specific item not found by ID.
/// * `ItemNotFoundGeneric` - Generic item not found (no ID specified).
/// * `InvalidInput(String)` - User or config input validation failure with message.
/// * `Compression(String)` - Compression/decompression errors with details.
/// * `Other(anyhow::Error)` - Catch-all for other anyhow-wrapped errors.
/// * `Migration(rusqlite_migration::Error)` - Database migration failures.
#[derive(Error, Debug)]
pub enum CoreError {
    #[error("Database error: {0}")]
    /// Database operation failed.
    Database(#[from] rusqlite::Error),
    #[error("I/O error: {0}")]
    /// File or stream I/O operation failed.
    Io(#[from] std::io::Error),
    #[error("Item not found with id {0}")]
    /// Item with the specified ID does not exist in the database.
    ItemNotFound(i64),
    #[error("Item not found")]
    /// Item does not exist (no specific ID).
    ItemNotFoundGeneric,
    #[error("Invalid input: {0}")]
    /// Input validation failed.
    InvalidInput(String),
    #[error("Compression error: {0}")]
    /// Compression or decompression operation failed.
    Compression(String),
    #[error(transparent)]
    /// Other unexpected error.
    Other(#[from] anyhow::Error),
    #[error("Migration error: {0}")]
    /// Database schema migration failed.
    Migration(#[from] rusqlite_migration::Error),
}
