use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use uuid::Uuid;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, sqlx::Type)]
#[sqlx(type_name = "paper_run_status", rename_all = "lowercase")]
#[serde(rename_all = "lowercase")]
pub enum PaperRunStatus {
    Queued,
    Running,
    Complete,
    Failed,
    Cancelled,
}

#[derive(Debug, Clone, FromRow)]
pub struct PaperRunRow {
    pub id: Uuid,
    pub status: PaperRunStatus,
    pub mode: String,
    pub config: serde_json::Value,
    pub starts_at: DateTime<Utc>,
    pub finishes_at: DateTime<Utc>,
    pub risk_free_return: Decimal,
    pub result_summary: Option<serde_json::Value>,
    pub error_message: Option<String>,
    pub worker_id: Option<String>,
    pub created_at: DateTime<Utc>,
    pub started_at: Option<DateTime<Utc>>,
    pub completed_at: Option<DateTime<Utc>>,
    /// When set, the backtest replays candle data at this interval instead of raw trades.
    /// Valid values: '1m', '5m', '15m', '1h', '4h', '1d'. None means tick replay.
    pub candle_interval: Option<String>,
    /// FK to `strategies.id`. Set on all new runs; null for runs created before strategy tracking.
    pub strategy_id: Option<Uuid>,
}
