use serde::Deserialize;
use swym_dal::config::DatabaseConfig;

#[derive(Debug, Deserialize)]
pub struct ExecutorConfig {
    pub database: DatabaseConfig,

    /// How often to poll for queued runs (seconds)
    #[serde(default = "default_poll_interval_secs")]
    pub poll_interval_secs: u64,

    /// Maximum number of concurrent paper trade runs
    #[serde(default = "default_max_concurrent_runs")]
    pub max_concurrent_runs: usize,

    /// Worker ID for claiming runs (defaults to hostname)
    pub worker_id: Option<String>,

    /// Reset running runs older than this many seconds back to queued on startup
    #[serde(default = "default_stale_timeout_secs")]
    pub stale_timeout_secs: i64,
}

fn default_poll_interval_secs() -> u64 {
    5
}

fn default_max_concurrent_runs() -> usize {
    4
}

fn default_stale_timeout_secs() -> i64 {
    600 // 10 minutes
}
