use std::collections::HashMap;

use crate::modules::monitoring::alert_rule::prometheus_alert_rule::PrometheusAlertRule;

pub fn alert_high_memory_usage() -> PrometheusAlertRule {
    PrometheusAlertRule {
        alert: "HighMemoryUsage".into(),
        expr: "container_memory_working_set_bytes{container!=\"\",namespace!=\"\"} > 500000000"
            .into(),
        r#for: Some("2m".into()),
        labels: HashMap::from([("severity".into(), "warning".into())]),
        annotations: HashMap::from([
            ("summary".into(), "Pod is using high memory".into()),
            (
                "description".into(),
                "A pod is consuming more than 500Mi of memory.".into(),
            ),
        ]),
    }
}

pub fn alert_high_cpu_usage() -> PrometheusAlertRule {
    PrometheusAlertRule {
        alert: "HighCPUUsage".into(),
        expr: "rate(container_cpu_usage_seconds_total{container!=\"\",namespace!=\"\"}[1m]) > 0.9"
            .into(),
        r#for: Some("1m".into()),
        labels: HashMap::from([("severity".into(), "warning".into())]),
        annotations: HashMap::from([
            ("summary".into(), "Pod is using high CPU".into()),
            (
                "description".into(),
                "A pod is using more than 90% of a core over 1 minute.".into(),
            ),
        ]),
    }
}
