use std::{collections::HashMap, str::FromStr};

use non_blank_string_rs::NonBlankString;
use serde::Serialize;
use url::Url;

use crate::{
    modules::helm::chart::{HelmChartScore, HelmRepository},
    score::Score,
    topology::{HelmCommand, Topology},
};

#[derive(Debug, Serialize, Clone)]
pub struct CertManagerHelmScore {}

impl<T: Topology + HelmCommand> Score<T> for CertManagerHelmScore {
    fn create_interpret(&self) -> Box<dyn crate::interpret::Interpret<T>> {
        let mut values_overrides = HashMap::new();
        values_overrides.insert(
            NonBlankString::from_str("crds.enabled").unwrap(),
            "true".to_string(),
        );
        let values_overrides = Some(values_overrides);

        HelmChartScore {
            namespace: Some(NonBlankString::from_str("cert-manager").unwrap()),
            release_name: NonBlankString::from_str("cert-manager").unwrap(),
            chart_name: NonBlankString::from_str("jetstack/cert-manager").unwrap(),
            chart_version: None,
            values_overrides,
            values_yaml: None,
            create_namespace: true,
            install_only: true,
            repository: Some(HelmRepository::new(
                "jetstack".to_string(),
                Url::parse("https://charts.jetstack.io").unwrap(),
                true,
            )),
        }
        .create_interpret()
    }

    fn name(&self) -> String {
        format!("CertManagerHelmScore")
    }
}
