/**
 * TypeScript types matching the FastAPI Pydantic schemas.
 */

// Strategy types
export interface StrategyInfo {
  name: string
  display_name: string
  market_type: string
  default_leverage: number
  default_params: Record<string, unknown>
  grid_params: Record<string, unknown>
}

export interface StrategiesResponse {
  strategies: StrategyInfo[]
}

// Symbol/Data types
export interface SymbolInfo {
  symbol: string
  exchange: string
  market_type: string
  timeframes: string[]
  start_date: string | null
  end_date: string | null
  row_count: number
}

export interface DataStatusResponse {
  symbols: SymbolInfo[]
}

// Backtest types
export interface BacktestRequest {
  strategy: string
  symbol: string
  exchange?: string
  timeframe?: string
  market_type?: string
  start_date?: string | null
  end_date?: string | null
  init_cash?: number
  leverage?: number | null
  fees?: number | null
  slippage?: number
  sl_stop?: number | null
  tp_stop?: number | null
  sl_trail?: boolean
  params?: Record<string, unknown>
}

export interface TradeRecord {
  entry_time: string
  exit_time: string | null
  entry_price: number
  exit_price: number | null
  size: number
  direction: string
  pnl: number | null
  return_pct: number | null
  status: string
}

export interface EquityPoint {
  timestamp: string
  value: number
  drawdown: number
}

export interface BacktestMetrics {
  total_return: number
  benchmark_return: number
  alpha: number
  sharpe_ratio: number
  max_drawdown: number
  win_rate: number
  total_trades: number
  profit_factor: number | null
  avg_trade_return: number | null
  total_fees: number
  total_funding: number
  liquidation_count: number
  liquidation_loss: number
  adjusted_return: number | null
}

export interface BacktestResult {
  run_id: string
  strategy: string
  symbol: string
  market_type: string
  timeframe: string
  start_date: string
  end_date: string
  leverage: number
  params: Record<string, unknown>
  metrics: BacktestMetrics
  equity_curve: EquityPoint[]
  trades: TradeRecord[]
  created_at: string
}

export interface BacktestSummary {
  run_id: string
  strategy: string
  symbol: string
  market_type: string
  timeframe: string
  total_return: number
  sharpe_ratio: number
  max_drawdown: number
  total_trades: number
  created_at: string
  params: Record<string, unknown>
}

export interface BacktestListResponse {
  runs: BacktestSummary[]
  total: number
}

// Comparison types
export interface CompareRequest {
  run_ids: string[]
}

export interface CompareResult {
  runs: BacktestResult[]
  param_diff: Record<string, unknown[]>
}
