use std::sync::{Arc, Mutex};

use serde::Serialize;

use super::{helm::config::KubePrometheusConfig, prometheus::Prometheus};
use crate::{
    score::Score,
    topology::{
        HelmCommand, Topology,
        oberservability::monitoring::{AlertReceiver, AlertRule, AlertingInterpret},
    },
};

#[derive(Clone, Debug, Serialize)]
pub struct HelmPrometheusAlertingScore {
    pub receivers: Vec<Box<dyn AlertReceiver<Prometheus>>>,
    pub rules: Vec<Box<dyn AlertRule<Prometheus>>>,
}

impl<T: Topology + HelmCommand> Score<T> for HelmPrometheusAlertingScore {
    fn create_interpret(&self) -> Box<dyn crate::interpret::Interpret<T>> {
        Box::new(AlertingInterpret {
            sender: Prometheus {
                config: Arc::new(Mutex::new(KubePrometheusConfig::new())),
            },
            receivers: self.receivers.clone(),
            rules: self.rules.clone(),
        })
    }
    fn name(&self) -> String {
        "HelmPrometheusAlertingScore".to_string()
    }
}
