use std::net::{SocketAddr, SocketAddrV4};

use harmony::{
    inventory::Inventory,
    maestro::Maestro,
    modules::{
        dns::DnsScore,
        dummy::{ErrorScore, PanicScore, SuccessScore},
        load_balancer::LoadBalancerScore,
    },
    topology::{
        BackendServer, DummyInfra, HealthCheck, HttpMethod, HttpStatusCode, LoadBalancerService,
    },
};
use harmony_macros::ipv4;

#[tokio::main]
async fn main() {
    let inventory = Inventory::autoload();
    let topology = DummyInfra {};
    let mut maestro = Maestro::initialize(inventory, topology).await.unwrap();

    maestro.register_all(vec![
        Box::new(SuccessScore {}),
        Box::new(ErrorScore {}),
        Box::new(PanicScore {}),
        Box::new(DnsScore::new(vec![], None)),
        Box::new(build_large_score()),
    ]);
    harmony_tui::init(maestro).await.unwrap();
}

fn build_large_score() -> LoadBalancerScore {
    let backend_server = BackendServer {
        address: "192.168.0.0".to_string(),
        port: 342,
    };
    let lb_service = LoadBalancerService {
        backend_servers: vec![
            backend_server.clone(),
            backend_server.clone(),
            backend_server.clone(),
        ],
        listening_port: SocketAddr::V4(SocketAddrV4::new(ipv4!("192.168.0.0"), 49387)),
        health_check: Some(HealthCheck::HTTP(
            "/some_long_ass_path_to_see_how_it_is_displayed_but_it_has_to_be_even_longer"
                .to_string(),
            HttpMethod::GET,
            HttpStatusCode::Success2xx,
        )),
    };
    LoadBalancerScore {
        public_services: vec![
            lb_service.clone(),
            lb_service.clone(),
            lb_service.clone(),
            lb_service.clone(),
            lb_service.clone(),
            lb_service.clone(),
        ],
        private_services: vec![
            lb_service.clone(),
            lb_service.clone(),
            lb_service.clone(),
            lb_service.clone(),
            lb_service.clone(),
            lb_service.clone(),
        ],
    }
}
