/**
 * 共享类型定义
 */

export interface SystemStatus {
  accounts: number
  activeConnections: number
  totalTrades: number
  totalVolume: string
  uptime: number
  lastUpdate: number
}

export interface TradingSignal {
  symbol: string
  action: 'buy' | 'sell' | 'hedge' | 'volume_boost' | 'close_position' | 'balance_accounts'
  side?: 'buy' | 'sell'
  amount: string
  price?: string
  confidence: number
  reason: string
  reduceOnly?: boolean
  targetAccount?: string
  stopLoss?: number
  takeProfit?: number
  enableTrailing?: boolean
}

export interface AccountState {
  totalTrades: number
  netPosition: number
  totalVolume: number
  lastBalance: number
  availableBalance: number
  marginUsed: number
  needsRebalance: boolean
  // 新增仓位详细信息
  entryPrice?: number
  unrealizedPnl?: number
  currentPrice?: number
  positionValue?: number
  leverage?: number
}

export interface BasisDataPoint {
  spotPrice: number
  futuresPrice: number
  basis: number
  basisPercent: number
  timestamp: number
}

export interface BasisRiskAssessment {
  riskLevel: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL'
  currentBasis: number | null
  confidence: number
  message: string
  timestamp: number
}

export interface StopLossOrder {
  orderId: string
  symbol: string
  amount: string
  stopPrice: number
  side: 'buy' | 'sell'
  accountId: string
  timestamp: number
  isActive: boolean
}

export interface TakeProfitOrder {
  orderId: string
  symbol: string
  amount: string
  targetPrice: number
  side: 'buy' | 'sell'
  accountId: string
  timestamp: number
  isActive: boolean
}

export interface RiskScore {
  riskScore: number
  riskLevel: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL'
  riskFactors: string[]
  recommendations: string[]
}

export interface CacheEntry {
  data: any
  timestamp: number
  ttl: number
}

export interface ServiceConfig {
  enabled: boolean
  settings: Record<string, any>
}

export interface ServiceStatus {
  name: string
  status: 'running' | 'stopped' | 'error'
  lastUpdate: number
  details?: any
}

export interface DashboardData {
  timestamp: number
  accounts: {
    total: number
    totalBalance: number
    totalNetPosition: number
    accountDetails: Array<{
      id: string
      balance: number
      available: number
      position: number
      marginUsed: number
    }>
  }
  trading: {
    totalTrades: number
    successfulTrades: number
    failedTrades: number
    successRate: number
    totalVolume: number
    lastTradeTime: number
  }
  risk: {
    riskScore: number
    riskLevel: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL'
    riskFactors: string[]
    recommendations: string[]
    basisRisk: {
      level: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL'
      currentBasis: number | null
      message: string
    }
  }
  stopLoss: {
    activeStopLoss: number
    activeTakeProfit: number
    monitoringSymbols: number
  }
  hedging: {
    hedgePairs: number
    autoHedgingEnabled: boolean
    totalNetExposure: number
  }
  cache: {
    totalEntries: number
    hitRate: number
    memoryUsage: string
  }
  system: {
    services: { [serviceName: string]: string }
    uptime: number
    version: string
  }
}

export interface TradingService {
  initialize(): Promise<void>
  start(): Promise<void>
  stop(): Promise<void>
  getStatus(): ServiceStatus
}
