pub mod capture;
pub mod compactor;
pub mod filter;

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SignalKind {
    Build,
    Test,
    Lint,
    Query,
    Script,
    Package,
    Infra,
    Database,
    System,
    Unknown,
}

impl SignalKind {
    pub fn from_program(program: &str, args: &[String]) -> Self {
        let prog = program.split('/').next_back().unwrap_or(program);
        match prog {
            "git" | "gh" | "jj" => Self::Query,
            "cargo" => {
                let sub = args.first().map(|s| s.as_str()).unwrap_or("");
                match sub {
                    "test" | "nextest" => Self::Test,
                    "build" | "check" | "clippy" => Self::Build,
                    _ => Self::Build,
                }
            }
            "go" => {
                let sub = args.first().map(|s| s.as_str()).unwrap_or("");
                if sub == "test" {
                    Self::Test
                } else {
                    Self::Build
                }
            }
            "make" | "cmake" | "bazel" | "gradle" | "mvn" => Self::Build,
            "npm" | "pnpm" | "yarn" | "bun" | "pip" => Self::Package,
            "pytest" | "jest" | "vitest" | "rspec" => Self::Test,
            "eslint" | "ruff" | "mypy" | "golangci-lint" | "clippy" => Self::Lint,
            "docker" | "kubectl" | "terraform" | "aws" | "helm" => Self::Infra,
            "psql" | "mysql" | "sqlite3" | "prisma" => Self::Database,
            "ls" | "find" | "grep" | "cat" | "env" => Self::System,
            _ => Self::Unknown,
        }
    }
}
