//! Per-component probe dispatch.
//!
//! Maps component names to the shell commands that verify liveness.
//! Tier: mode → component → probe command string.

use std::collections::HashMap;

/// Returns the SSH command that probes a taskserv-mode component for liveness.
pub fn taskserv_probe_command(component: &str) -> Option<String> {
    let table: HashMap<&str, &str> = [
        ("k0s", "systemctl is-active k0scontroller"),
        ("k0s-worker", "systemctl is-active k0sworker"),
        ("postgresql", "pg_isready -q"),
        ("external_nfs", "showmount -e localhost"),
        ("democratic_csi", "systemctl is-active democratic-csi"),
        ("hetzner_csi", "systemctl is-active hetzner-csi"),
        ("cilium", "systemctl is-active cilium"),
        ("coredns", "systemctl is-active coredns"),
        ("etcd", "systemctl is-active etcd"),
        ("containerd", "systemctl is-active containerd"),
        ("crio", "systemctl is-active crio"),
    ]
    .into_iter()
    .collect();

    table.get(component).map(|s| s.to_string())
}

/// Returns the SSH command (run on the cluster controller) that probes a cluster-mode component.
///
/// Uses `k0s kubectl` since the cluster controller runs k0s.
pub fn cluster_probe_command(component: &str, namespace: &str) -> String {
    // kubectl get deploy checks readyReplicas ≥ 1
    format!(
        "k0s kubectl get deploy -n {namespace} {component} -o jsonpath='{{.status.readyReplicas}}' 2>/dev/null | grep -qE '^[1-9]'"
    )
}

/// Returns the SSH command that probes a container-mode component for liveness.
pub fn container_probe_command(component: &str) -> String {
    format!("docker inspect --format='{{{{.State.Running}}}}' {component} | grep -q true")
}
