use std::collections::BTreeMap;

use super::crd_prometheus_rules::Rule;

pub fn build_rule_container_restarting() -> Rule {
    Rule {
        alert: Some("ContainerRestarting".into()),
        expr: Some("increase(kube_pod_container_status_restarts_total[5m]) > 3".into()),
        for_: Some("5m".into()),
        labels: Some(BTreeMap::from([("severity".into(), "warning".into())])),
        annotations: Some(BTreeMap::from([
            (
                "summary".into(),
                "Container is restarting frequently".into(),
            ),
            (
                "description".into(),
                "Container in this namespace is restarting more than 3 times in 5 minutes.".into(),
            ),
        ])),
    }
}

pub fn build_rule_pod_failed() -> Rule {
    Rule {
        alert: Some("PodFailed".into()),
        expr: Some("kube_pod_status_phase{phase=\"Failed\"} > 0".into()),
        for_: Some("0m".into()),
        labels: Some(BTreeMap::from([("severity".into(), "critical".into())])),
        annotations: Some(BTreeMap::from([
            ("summary".into(), "A pod has failed".into()),
            (
                "description".into(),
                "One or more pods are in Failed phase.".into(),
            ),
        ])),
    }
}
