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>,
    #[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"),
        }
    }
}
