class EmergencyAutomation {
  private static isRunning = false
  private static lastStart = 0
  private static readonly MIN_START_INTERVAL = 5 * 60 * 1000 // 5 minutes

  static async start(config: any) {
    const now = Date.now()
    if (now - this.lastStart < this.MIN_START_INTERVAL) {
      return { 
        success: false, 
        message: `Emergency rate limit: Wait ${Math.ceil((this.MIN_START_INTERVAL - (now - this.lastStart)) / 1000)} seconds`
      }
    }

    if (this.isRunning) {
      return { success: false, message: 'Automation already running' }
    }

    this.isRunning = true
    this.lastStart = now
    console.log('🛡️ EMERGENCY: Starting with rate limits')
    
    return { success: true, message: 'Emergency safe mode activated' }
  }

  static async stop() {
    this.isRunning = false
    console.log('⛔ EMERGENCY: Stopped automation')
    return { success: true, message: 'Emergency stop completed' }
  }

  static getStatus() {
    return {
      isActive: this.isRunning,
      mode: 'EMERGENCY_SAFE',
      symbol: 'SOLUSD',
      timeframe: '1h',
      totalTrades: 0,
      successfulTrades: 0,
      winRate: 0,
      totalPnL: 0,
      errorCount: 0,
      nextAnalysisIn: 0,
      analysisInterval: 3600,
      currentCycle: 0
    }
  }
}

export const emergencyAutomation = EmergencyAutomation
