#![allow(dead_code)]
//! Training and environment commands

use crate::dev::{DevState, TrainingEnvironment, TrainingTask};
use anyhow::Result;
use dialoguer::Select;

/// Launch training task
pub async fn launch_training(_state: &DevState) -> Result<()> {
    println!("\n╭─────────────────────────────────────────╮");
    println!("│  Launch Training Task                    │");
    println!("╰─────────────────────────────────────────╯\n");

    let tasks = TrainingTask::all();
    let task_names: Vec<&str> = tasks.iter().map(|t| t.name()).collect();
    let mut items = task_names;
    items.push("Custom...");

    let selection = Select::new()
        .with_prompt("Select training task")
        .items(&items)
        .default(0)
        .interact()?;

    if selection >= tasks.len() {
        println!("  Custom task selection coming soon!");
        return Ok(());
    }

    let selected_task = &tasks[selection];
    println!("  Launching training task: {}", selected_task);
    println!("  Feature coming soon - will submit job to training system");

    Ok(())
}

/// Change environment
pub async fn change_environment(state: &mut DevState) -> Result<()> {
    println!("\n╭─────────────────────────────────────────╮");
    println!("│  Change Environment                      │");
    println!("╰─────────────────────────────────────────╯\n");

    let environments = TrainingEnvironment::all();
    let env_names: Vec<&str> = environments.iter().map(|e| e.name()).collect();

    let selection = Select::new()
        .with_prompt("Select environment")
        .items(&env_names)
        .default(0)
        .interact()?;

    state.current_env = environments[selection].name().to_string();
    println!("  Environment changed to: {}", state.current_env);

    Ok(())
}

/// Change training task
pub async fn change_task(state: &mut DevState) -> Result<()> {
    println!("\n╭─────────────────────────────────────────╮");
    println!("│  Change Training Task                    │");
    println!("╰─────────────────────────────────────────╯\n");

    let tasks = TrainingTask::all();
    let task_names: Vec<&str> = tasks.iter().map(|t| t.name()).collect();

    let selection = Select::new()
        .with_prompt("Select training task")
        .items(&task_names)
        .default(0)
        .interact()?;

    state.current_task = tasks[selection].name().to_string();
    println!("  Task changed to: {}", state.current_task);

    Ok(())
}
