// Singleton automation instance manager with learning integration
let automationInstance = null;

async function createAutomationInstance() {
  try {
    // Use the working simple automation directly
    const { simpleAutomation } = await import('./simple-automation.js');
    console.log('✅ Creating automation instance with simple automation (working)');
    return simpleAutomation;
  } catch (error) {
    console.error('❌ Could not create automation instance:', error);
    throw new Error('No automation system available');
  }
}

async function getAutomationInstance() {
  if (!automationInstance) {
    automationInstance = await createAutomationInstance();
  }
  return automationInstance;
}

async function resetAutomationInstance() {
  if (automationInstance) {
    console.log('🔄 Resetting automation instance');
    if (typeof automationInstance.stop === 'function') {
      await automationInstance.stop();
    }
  }
  automationInstance = null;
}

export {
  getAutomationInstance,
  resetAutomationInstance
};
