use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RunnerSpec {
    pub cpu: u32,
    pub memory_gb: u32,
    pub disk_gb: u32,
    pub time_budget_min: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RunnerLease {
    pub lease_id: Uuid,
    /// Opaque handle returned by `runner.nu spawn`; passed verbatim to `runner.nu destroy`.
    pub runner_handle: String,
    pub ssh_host: String,
    pub ssh_port: u16,
    pub spec: RunnerSpec,
    pub workspace: String,
    pub created_at: DateTime<Utc>,
    pub expires_at: DateTime<Utc>,
}

#[derive(Debug, Deserialize)]
pub struct SpawnRequest {
    pub cpu: u32,
    pub memory_gb: u32,
    pub disk_gb: u32,
    pub time_budget_min: u32,
    pub workspace: String,
    /// Image reference passed to the runner — label selector (e.g. `app=buildkit-runner-golden`)
    /// or a direct image ID/name. Interpretation is left to the runner script.
    pub image: String,
}

#[derive(Debug, Serialize)]
pub struct SpawnResponse {
    pub lease_id: Uuid,
    pub ssh_host: String,
    pub ssh_port: u16,
    pub expires_at: String,
}

#[derive(Debug, Serialize)]
pub struct P95Stats {
    pub cpu_p95: f64,
    pub memory_mb_p95: f64,
    pub duration_secs_p95: f64,
    pub sample_count: u64,
}

