use std::collections::BTreeMap;

use async_trait::async_trait;
use serde::Serialize;
use serde_yaml::{Mapping, Sequence, Value};

use crate::modules::monitoring::alert_rule::prometheus_alert_rule::AlertManagerRuleGroup;

#[async_trait]
pub trait AlertChannelConfig {
    async fn get_config(&self) -> AlertManagerChannelConfig;
}

#[derive(Debug, Clone, Serialize)]
pub struct AlertManagerValues {
    pub alertmanager: AlertManager,
}
#[derive(Debug, Clone, Serialize)]
pub struct AlertManager {
    pub enabled: bool,
    pub config: AlertManagerConfig,
}

#[derive(Debug, Clone, Serialize)]
pub struct AlertManagerConfig {
    pub global: Mapping,
    pub route: AlertManagerRoute,
    pub receivers: Sequence,
}

#[derive(Debug, Clone, Serialize)]
pub struct AlertManagerRoute {
    pub routes: Sequence,
}

#[derive(Debug, Clone, Serialize)]
pub struct AlertManagerChannelConfig {
    ///expecting an option that contains two values
    ///if necessary for the alertchannel
    ///[ jira_api_url: <string> ]
    pub channel_global_config: Option<(Value, Value)>,
    pub channel_route: Value,
    pub channel_receiver: Value,
}

#[derive(Debug, Clone, Serialize)]
pub struct AlertManagerAdditionalPromRules {
    #[serde(flatten)]
    pub rules: BTreeMap<String, AlertGroup>,
}

#[derive(Debug, Clone, Serialize)]
pub struct AlertGroup {
    pub groups: Vec<AlertManagerRuleGroup>,
}
