use harmony::{
    inventory::Inventory,
    maestro::Maestro,
    modules::{
        monitoring::{
            alert_channel::discord_alert_channel::DiscordWebhook,
            alert_rule::prometheus_alert_rule::AlertManagerRuleGroup,
            kube_prometheus::helm_prometheus_alert_score::HelmPrometheusAlertingScore,
        },
        prometheus::alerts::{
            infra::dell_server::{
                alert_global_storage_status_critical, alert_global_storage_status_non_recoverable,
                global_storage_status_degraded_non_critical,
            },
            k8s::pvc::high_pvc_fill_rate_over_two_days,
        },
    },
    topology::{K8sAnywhereTopology, Url},
};

#[tokio::main]
async fn main() {
    let discord_receiver = DiscordWebhook {
        name: "test-discord".to_string(),
        url: Url::Url(url::Url::parse("https://discord.doesnt.exist.com").unwrap()),
    };

    let high_pvc_fill_rate_over_two_days_alert = high_pvc_fill_rate_over_two_days();
    let dell_system_storage_degraded = global_storage_status_degraded_non_critical();
    let alert_global_storage_status_critical = alert_global_storage_status_critical();
    let alert_global_storage_status_non_recoverable = alert_global_storage_status_non_recoverable();

    let additional_rules =
        AlertManagerRuleGroup::new("pvc-alerts", vec![high_pvc_fill_rate_over_two_days_alert]);
    let additional_rules2 = AlertManagerRuleGroup::new(
        "dell-server-alerts",
        vec![
            dell_system_storage_degraded,
            alert_global_storage_status_critical,
            alert_global_storage_status_non_recoverable,
        ],
    );

    let alerting_score = HelmPrometheusAlertingScore {
        receivers: vec![Box::new(discord_receiver)],
        rules: vec![Box::new(additional_rules), Box::new(additional_rules2)],
    };
    let mut maestro = Maestro::<K8sAnywhereTopology>::initialize(
        Inventory::autoload(),
        K8sAnywhereTopology::from_env(),
    )
    .await
    .unwrap();

    maestro.register_all(vec![Box::new(alerting_score)]);
    harmony_cli::init(maestro, None).await.unwrap();
}
