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

use non_blank_string_rs::NonBlankString;

use crate::modules::{
    helm::chart::HelmChartScore, monitoring::prometheus::prometheus_config::PrometheusConfig,
};

pub fn prometheus_helm_chart_score(config: Arc<Mutex<PrometheusConfig>>) -> HelmChartScore {
    let config = config.lock().unwrap();
    let ns = config.namespace.clone().unwrap();
    let values = format!(
        r#"
rbac:
  create: true
kube-state-metrics:
  enabled: false
nodeExporter:
  enabled: false
alertmanager:
  enabled: false
pushgateway:
  enabled: false
server:
  serviceAccount:
    create: false
  rbac:
    create: true
fullnameOverride: prometheus-{ns}
"#
    );
    HelmChartScore {
        namespace: Some(NonBlankString::from_str(&config.namespace.clone().unwrap()).unwrap()),
        release_name: NonBlankString::from_str("prometheus").unwrap(),
        chart_name: NonBlankString::from_str(
            "oci://ghcr.io/prometheus-community/charts/prometheus",
        )
        .unwrap(),
        chart_version: None,
        values_overrides: None,
        values_yaml: Some(values.to_string()),
        create_namespace: true,
        install_only: true,
        repository: None,
    }
}
