// #![allow(clippy::print_literal)]
use super::{gdt, interrupts};
use crate::{
    logger,
    scheduler::{capabilities::Capabilities, SCHEDULER},
    serial_println,
};

/// x86_64 initialization
pub fn init() {
    use crate::{
        network::socket::SimpleSock, relib::network::socket::Socket,
        scheduler::priority::Priority::High, stdio::StdIO,
    };

    let mut log_socket_id = SimpleSock::new();
    log_socket_id.register_protocol("Logger".to_string());

    let result = logger::init();
    match result {
        Ok(_) => {
            serial_println!("Logger initialized");
        }
        Err(err) => error!("{}", err),
    }

    gdt::init();

    let mut scheduler = SCHEDULER.lock();
    let process_0 = scheduler.new_process(
        Capabilities::empty(),
        High,
        "".to_string(),
        StdIO::new("null".to_string()),
    );
    scheduler.add_process(process_0);
    drop(scheduler);

    interrupts::init_idt();
    unsafe { interrupts::PICS.lock().initialize() };
    x86_64::instructions::interrupts::enable();
}
