use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
    #[cfg(feature = "postgres")]
    #[error("Database error: {0}")]
    Database(#[from] sqlx::Error),

    #[cfg(feature = "postgres")]
    #[error("Migration error: {0}")]
    Migration(#[from] sqlx::migrate::MigrateError),

    #[error("Serialization error: {0}")]
    Serialization(#[from] serde_json::Error),

    #[error("UUID error: {0}")]
    Uuid(#[from] uuid::Error),

    #[error("Job not found: {0}")]
    JobNotFound(String),

    #[error("Job execution failed: {0}")]
    JobExecutionFailed(String),

    #[error("Invalid job state transition")]
    InvalidStateTransition,

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

    #[error("Configuration error: {0}")]
    Config(String),

    #[error(transparent)]
    Other(#[from] anyhow::Error),
}

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