use crate::api::types::{BillingInfo, Model};

use super::base_table;

pub fn billing(info: &BillingInfo) {
    let mut table = base_table();
    table.set_header(vec!["Field", "Value"]);

    table.add_row(vec!["Plan", &info.plan.name]);
    table.add_row(vec!["Credits Left", &info.total_credits_left.to_string()]);
    table.add_row(vec![
        "Monthly Usage",
        &format!("{} / {}", info.monthly_usage, info.monthly_limit),
    ]);
    table.add_row(vec!["Active", &info.is_active.to_string()]);
    table.add_row(vec!["Period", &info.period]);
    if let Some(ref renew) = info.renews_on {
        table.add_row(vec!["Renews On", renew]);
    }
    println!("{table}");
}

pub fn models(models: &[Model]) {
    let mut table = base_table();
    table.set_header(vec![
        "Name",
        "Key",
        "Default",
        "Max Prompt",
        "Max Tags",
        "Description",
    ]);

    for model in models {
        if !model.can_use {
            continue;
        }
        table.add_row(vec![
            &model.name,
            &model.external_key,
            &if model.is_default_model {
                "yes".into()
            } else {
                String::new()
            },
            &model.max_lengths.prompt.to_string(),
            &model.max_lengths.tags.to_string(),
            &model.description,
        ]);
    }
    println!("{table}");
}
