//! JSON wrappers for car-scheduler functions.

/// Create a task definition from parameters. Returns task JSON.
pub fn create_task(
    name: &str,
    prompt: &str,
    trigger: Option<&str>,
    schedule: Option<&str>,
    system_prompt: Option<&str>,
) -> Result<String, String> {
    let mut task = car_scheduler::Task::new(name, prompt);
    if let Some(t) = trigger {
        let trigger_type = match t {
            "once" => car_scheduler::TaskTrigger::Once,
            "cron" => car_scheduler::TaskTrigger::Cron,
            "interval" => car_scheduler::TaskTrigger::Interval,
            "file_watch" => car_scheduler::TaskTrigger::FileWatch,
            _ => car_scheduler::TaskTrigger::Manual,
        };
        task = task.with_trigger(trigger_type, schedule.unwrap_or(""));
    }
    if let Some(sp) = system_prompt {
        task = task.with_system_prompt(sp);
    }
    serde_json::to_string(&task).map_err(|e| e.to_string())
}
