export enum OrderSide {
  BUY = 'buy',
  SELL = 'sell',
}

export enum OrderType {
  MARKET = 'market',
  LIMIT = 'limit',
  STOP_LOSS = 'stop_loss',
  TAKE_PROFIT = 'take_profit',
  TRAILING_STOP = 'trailing_stop',
  OCO = 'oco',
  ICEBERG = 'iceberg',
}

export enum OrderStatus {
  PENDING = 'pending',
  OPEN = 'open',
  PARTIALLY_FILLED = 'partially_filled',
  FILLED = 'filled',
  CANCELLED = 'cancelled',
  REJECTED = 'rejected',
  EXPIRED = 'expired',
}

export interface OrderCreate {
  exchange_id: number
  symbol: string
  side: OrderSide
  order_type: OrderType
  quantity: number
  price?: number
  strategy_id?: number
  paper_trading?: boolean
}

export interface OrderResponse {
  id: number
  exchange_id: number
  strategy_id?: number
  symbol: string
  order_type: OrderType
  side: OrderSide
  status: OrderStatus
  quantity: number
  price?: number
  filled_quantity: number
  average_fill_price?: number
  fee: number
  paper_trading: boolean
  created_at: string
  updated_at: string
  filled_at?: string
}

export interface PositionResponse {
  symbol: string
  quantity: number
  entry_price: number
  current_price: number
  unrealized_pnl: number
  realized_pnl: number
}

export interface PortfolioResponse {
  positions: Array<{
    symbol: string
    quantity: number
    entry_price: number
    current_price: number
    unrealized_pnl: number
  }>
  performance: {
    current_value: number
    unrealized_pnl: number
    realized_pnl: number
  }
  timestamp: string
}

export interface PortfolioHistoryResponse {
  dates: string[]
  values: number[]
  pnl: number[]
}

export interface StrategyCreate {
  name: string
  description?: string
  strategy_type: string
  class_name: string
  parameters?: Record<string, any>
  timeframes?: string[]
  paper_trading?: boolean
  schedule?: Record<string, any>
}

export interface StrategyUpdate {
  name?: string
  description?: string
  parameters?: Record<string, any>
  timeframes?: string[]
  enabled?: boolean
  schedule?: Record<string, any>
}

export interface StrategyResponse {
  id: number
  name: string
  description?: string
  strategy_type: string
  class_name: string
  parameters: Record<string, any>
  timeframes: string[]
  enabled: boolean
  running: boolean
  paper_trading: boolean
  version: string
  schedule?: Record<string, any>
  created_at: string
  updated_at: string
}

export interface BacktestRequest {
  strategy_id: number
  symbol: string
  exchange: string
  timeframe: string
  start_date: string
  end_date: string
  initial_capital?: number
  slippage?: number
  fee_rate?: number
}

export interface BacktestResponse {
  backtest_id?: number
  results: Record<string, any>
  status: string
}

export interface ExchangeResponse {
  id: number
  name: string
  sandbox: boolean
  read_only: boolean
  enabled: boolean
  created_at: string
  updated_at: string
}
