//! Category classifier — mirrors the _gen-patterns.py CATEGORY_MAP.
//! Kept as a static const table so misclassifications are easy to
//! audit + fix in one place.

const MAP: &[(&str, &str)] = &[
    ("cargo", "rust"),
    ("rust-", "rust"),
    ("npm-", "npm"),
    ("python-", "python"),
    ("helm-", "helm"),
    ("caixa-", "caixa"),
    ("gem-", "ruby"),
    ("ansible-", "ansible"),
    ("go-", "language"),
    ("gradle-", "language"),
    ("maven-", "language"),
    ("dotnet-", "language"),
    ("swift-", "language"),
    ("xcodebuild", "language"),
    ("mix-", "language"),
    ("hex-", "language"),
    ("zig-", "language"),
    ("golangci-", "language"),
    ("goreleaser", "language"),
    ("wasm-", "language"),
    ("aws-", "cloud"),
    ("gcp-", "cloud"),
    ("cloudflare-", "cloud"),
    ("azure-", "cloud"),
    ("vercel-", "cloud"),
    ("netlify-", "cloud"),
    ("render-", "cloud"),
    ("railway-", "cloud"),
    ("heroku-", "cloud"),
    ("doctl-", "cloud"),
    ("fly-", "cloud"),
    ("datadog-", "observability"),
    ("grafana-", "observability"),
    ("honeycomb-", "observability"),
    ("prometheus-", "observability"),
    ("sentry-", "observability"),
    ("otel-", "observability"),
    ("loki-", "observability"),
    ("pyroscope-", "observability"),
    ("security-", "security"),
    ("sbom-", "security"),
    ("license-header", "security"),
    ("license-finder", "security"),
    ("provenance-", "security"),
    ("image-scan", "security"),
    ("cosign-", "security"),
    ("tfsec", "security"),
    ("checkov", "security"),
    ("bandit", "security"),
    ("gosec", "security"),
    ("conftest", "security"),
    ("kics-", "security"),
    ("snyk-", "security"),
    ("vault-", "security"),
    ("gh-secrets-", "security"),
    ("slsa-", "security"),
    ("cyclonedx-", "security"),
    ("secrets-scan", "security"),
    ("docker-", "container"),
    ("ko-", "container"),
    ("oci-", "container"),
    ("podman-", "container"),
    ("buildah-", "container"),
    ("skopeo-", "container"),
    ("crane-", "container"),
    ("buildkit-", "container"),
    ("kubectl-", "k8s"),
    ("flux-", "k8s"),
    ("argocd-", "k8s"),
    ("kustomize-", "k8s"),
    ("k8s-", "k8s"),
    ("velero-", "k8s"),
    ("helmfile-", "k8s"),
    ("tanka-", "k8s"),
    ("helm-deploy", "k8s"),
    ("helm-oci-publish", "helm"),
    ("terraform-", "iac"),
    ("pulumi-", "iac"),
    ("iac-", "iac"),
    ("db-", "db"),
    ("atlas-", "db"),
    ("prisma-", "db"),
    ("flyway-", "db"),
    ("sqitch-", "db"),
    ("playwright-", "frontend"),
    ("cypress-", "frontend"),
    ("storybook-", "frontend"),
    ("percy-", "frontend"),
    ("lighthouse-", "frontend"),
    ("fastlane-", "mobile"),
    ("app-store-", "mobile"),
    ("eas-", "mobile"),
    ("flutter-", "mobile"),
    ("slack-", "comms"),
    ("discord-", "comms"),
    ("email-", "comms"),
    ("pagerduty-", "comms"),
    ("matrix-", "comms"),
    ("teams-", "comms"),
    ("telegram-", "comms"),
    ("twilio-", "comms"),
    ("mattermost-", "comms"),
    ("nats-", "messaging"),
    ("kafka-", "messaging"),
    ("mkdocs-", "docs"),
    ("docusaurus-", "docs"),
    ("mdbook-", "docs"),
    ("hugo-", "docs"),
    ("vitepress-", "docs"),
    ("zola-", "docs"),
    ("changelog-", "docs"),
    ("docs-", "docs"),
    ("api-spec-", "docs"),
    ("toc-", "docs"),
    ("mutation-", "quality"),
    ("benchmark-", "quality"),
    ("sonarqube-", "quality"),
    ("pa11y-", "quality"),
    ("dependency-", "sdlc"),
    ("nix-flake-update", "sdlc"),
    ("pr-comment", "sdlc"),
    ("issue-create", "sdlc"),
    ("status-badge", "sdlc"),
    ("dependabot-", "sdlc"),
    ("changesets", "release-mgmt"),
    ("semantic-", "release-mgmt"),
    ("release-please", "release-mgmt"),
    ("release-promote", "release-mgmt"),
    ("yank-version", "release-mgmt"),
    ("onboard-", "sdlc"),
    ("akeyless-", "akeyless"),
    ("wireguard-", "networking"),
    ("tailscale-", "networking"),
    ("artifact-fetch", "storage"),
    ("s3-mirror", "storage"),
    ("gcs-sync", "storage"),
    ("restic-", "backup"),
    ("temporal-", "workflow"),
    ("airflow-", "workflow"),
    ("devcontainer-", "devx"),
    ("pre-commit-", "devx"),
    ("json-schema-", "data"),
    ("yaml-lint", "data"),
    ("nix-", "nix"),
    ("nix-flake-check", "validation"),
    ("branch-protect-", "hygiene"),
    ("codeowners-", "hygiene"),
    ("stale-", "hygiene"),
    ("gh-team-", "hygiene"),
    ("tlisp-lint", "validation"),
    ("action-shell-lint", "meta"),
    ("adoption-audit", "meta"),
    ("defaction-render", "meta"),
    ("tatara-script", "runtime"),
    ("git-", "git"),
    ("gh-", "gh"),
    ("derive-version-", "gh"),
    ("detect-repo-type", "dispatch"),
    ("spec-watch", "spec"),
    ("caixa-detect", "dispatch"),
    ("rust-gate", "validation"),
    ("npm-gate", "validation"),
    ("python-gate", "validation"),
    ("typecheck-", "validation"),
    ("rust-cross-", "build"),
    ("rust-workspace-publish", "publish"),
    ("rust-workspace-bump", "bump"),
    ("substrate-bump", "bump"),
];

pub fn categorize(name: &str) -> &'static str {
    // Longest-prefix match
    let mut best_match: Option<(usize, &'static str)> = None;
    for (prefix, cat) in MAP {
        if name == *prefix || name.starts_with(prefix) {
            if best_match.map_or(true, |(len, _)| prefix.len() > len) {
                best_match = Some((prefix.len(), cat));
            }
        }
    }
    best_match.map_or("uncategorized", |(_, c)| c)
}

pub fn intro(category: &str) -> &'static str {
    match category {
        "rust" => "🦀 Rust ecosystem",
        "npm" => "📦 npm ecosystem",
        "python" => "🐍 Python ecosystem",
        "helm" => "⛵ Helm — chart packaging + deployment",
        "caixa" => "📦 caixa — canonical SDLC primitive",
        "language" => "🌐 Multi-language (Go/Java/.NET/Swift/Elixir/Zig/WASM)",
        "cloud" => "☁️ Cloud providers",
        "k8s" => "☸️ Kubernetes — apply / deploy / reconcile / wait",
        "iac" => "🏗️ IaC — Terraform / Pulumi",
        "db" => "🗄️ Database — migrations + backups",
        "frontend" => "🖥️ Frontend testing + deployment",
        "mobile" => "📱 Mobile — Fastlane / App Store / EAS / Flutter",
        "observability" => "📊 Observability — markers / metrics / logs / profiles",
        "security" => "🔒 Security — vuln scans / SBOM / signing / secrets",
        "comms" => "💬 Notifications across N channels",
        "messaging" => "📡 Message brokers — NATS / Kafka",
        "docs" => "📚 Documentation generation + publishing",
        "quality" => "✅ Code quality — mutation / benchmark / SonarQube / accessibility",
        "sdlc" => "🔄 SDLC automation",
        "release-mgmt" => "📦 Release management — Changesets / semantic-release",
        "akeyless" => "🔑 Akeyless secret management",
        "networking" => "🌐 Networking — WireGuard / Tailscale",
        "storage" => "💾 Storage — S3 / GCS / cross-workflow",
        "backup" => "🛡️ Backup — restic",
        "workflow" => "⚙️ Workflow orchestration — Temporal / Airflow",
        "devx" => "🛠️ Developer experience",
        "data" => "📋 Data validation",
        "nix" => "❄️ Nix — build / cache push",
        "hygiene" => "🧹 Repo hygiene",
        "validation" => "🚦 Validation — per-language gates + universal lints",
        "meta" => "🪞 Meta — directive enforcement + audit + renderer",
        "runtime" => "⚙️ Runtime — tatara-script",
        "git" => "📝 Git operations",
        "gh" => "🐙 GitHub API",
        "dispatch" => "🚏 Repo-type dispatch",
        "spec" => "📐 Spec watching",
        "container" => "🐋 Container build (Docker / ko / buildah / podman)",
        "build" => "🔨 Build — cross-compile / OCI / Ansible",
        "bump" => "⬆️ Version bumping",
        "publish" => "📤 Registry publishing",
        "ruby" => "💎 Ruby gem",
        "ansible" => "🅰️ Ansible Collection",
        _ => "🔧 Uncategorized — needs a home",
    }
}
