use std::sync::Arc;

use kube::CustomResource;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::topology::{
    k8s::K8sClient,
    oberservability::monitoring::{AlertReceiver, AlertSender},
};

#[derive(CustomResource, Serialize, Deserialize, Debug, Clone, JsonSchema)]
#[kube(
    group = "monitoring.coreos.com",
    version = "v1alpha1",
    kind = "AlertmanagerConfig",
    plural = "alertmanagerconfigs",
    namespaced
)]
pub struct AlertmanagerConfigSpec {
    #[serde(flatten)]
    pub data: serde_json::Value,
}

#[derive(Debug, Clone, Serialize)]
pub struct CRDPrometheus {
    pub namespace: String,
    pub client: Arc<K8sClient>,
}

impl AlertSender for CRDPrometheus {
    fn name(&self) -> String {
        "CRDAlertManager".to_string()
    }
}

impl Clone for Box<dyn AlertReceiver<CRDPrometheus>> {
    fn clone(&self) -> Self {
        self.clone_box()
    }
}

impl Serialize for Box<dyn AlertReceiver<CRDPrometheus>> {
    fn serialize<S>(&self, _serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        todo!()
    }
}
