use serde::{Deserialize, Serialize};

pub use config::hook::PoolConfig;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HookTask {
    pub id: String,
    pub repo_id: String,
    pub task_type: TaskType,
    pub payload: serde_json::Value,
    pub created_at: chrono::DateTime<chrono::Utc>,
    /// Number of times this task has been retried after a failure.
    /// When >= MAX_TASK_RETRIES, the task is discarded instead of requeued.
    #[serde(default)]
    pub retry_count: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum TaskType {
    Sync,
    Fsck,
    Gc,
}

impl std::fmt::Display for TaskType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            TaskType::Sync => write!(f, "sync"),
            TaskType::Fsck => write!(f, "fsck"),
            TaskType::Gc => write!(f, "gc"),
        }
    }
}

#[derive(Debug, Clone)]
pub struct PoolMetrics {
    pub running: usize,
    pub max_concurrent: usize,
    pub cpu_usage: f32,
    pub total_processed: u64,
    pub total_failed: u64,
    pub can_accept: bool,
}
