use k8s_openapi::api::core::v1::Namespace;
use non_blank_string_rs::NonBlankString;
use serde::Serialize;
use serde_json::json;

use crate::{
    interpret::Interpret,
    score::Score,
    topology::{K8sclient, Topology},
};

#[derive(Debug, Clone, Serialize)]
pub struct K8sNamespaceScore {
    pub name: Option<NonBlankString>,
}

impl<T: Topology + K8sclient> Score<T> for K8sNamespaceScore {
    fn create_interpret(&self) -> Box<dyn Interpret<T>> {
        let name = match &self.name {
            Some(name) => name,
            None => todo!(
                "Return NoOp interpret when no namespace specified or something that makes sense"
            ),
        };
        let _namespace: Namespace = serde_json::from_value(json!(
            {
                "apiVersion": "v1",
                "kind": "Namespace",
                "metadata": {
                    "name": name,
                },
            }
        ))
        .unwrap();
        todo!(
            "We currently only support namespaced ressources (see Scope = NamespaceResourceScope)"
        );
        // Box::new(K8sResourceInterpret {
        //     score: K8sResourceScore::single(namespace.clone()),
        // })
    }

    fn name(&self) -> String {
        "K8sNamespaceScore".to_string()
    }
}
