use cli_table::{print_stdout, Cell, Style, Table};
use test_smi_rs::list_devices;
use test_smi_rs::SmiResult;

fn main() -> SmiResult<()> {
    let devices = list_devices()?;

    let mut rows = Vec::with_capacity(devices.len() + 1);
    let mut header = Vec::with_capacity(devices.len() + 1);
    header.push("Device".cell().bold(true));

    for device in devices.iter() {
        let name = device.device_info()?.name();
        header.push(name.cell().bold(true));
    }
    rows.push(header);

    for device1 in devices.iter() {
        let mut row = Vec::with_capacity(devices.len() + 1);
        row.push(device1.device_info()?.name().cell());
        for device2 in devices.iter() {
            let link_type = device1.device_to_device_link_type(device2)?;
            row.push(link_type.cell());
        }
        rows.push(row);
    }

    let table = rows.table();
    print_stdout(table).expect("couldn't print table");

    Ok(())
}