use crate::utils::database::Database;
use anyhow::Result;
use console::style;
use log::debug;

pub(crate) fn display_database(arguments: &super::cli::Arguments) -> Result<()> {
    println!("Displaying the database schema generated by GeekORM...\n");

    let database = Database::find_database(arguments)?;
    debug!("Database: {:#?}", database);

    for table in database.tables {
        println!(" Table({}) {{", style(table.name).green());

        for column in table.columns {
            if column.skip {
                continue;
            }

            println!(
                "    Column({}, {})",
                style(column.name).blue(),
                style(column.column_type).yellow()
            );
        }

        println!(" }}\n");
    }

    Ok(())
}
