/**
 * AdsPower ActionFactory
 * 创建基于Puppeteer的Actions
 */

import { IActionFactory } from '../../../core/interfaces/IAction';
import ClickAction from '../actions/ClickAction';
import WaitAction from '../actions/WaitAction';
import NavigateAction from '../actions/NavigateAction';
import CustomAction from '../actions/CustomAction';
import VerifyAction from '../actions/VerifyAction';
import FillFormAction from '../actions/FillFormAction';
import ScrollAction from '../actions/ScrollAction';
import ExtractAction from '../actions/ExtractAction';
import RetryBlockAction from '../actions/RetryBlockAction';

export class AdsPowerActionFactory implements IActionFactory {
  private actions: Map<string, any>;

  constructor() {
    this.actions = new Map();
    this.registerDefaultActions();
  }

  private registerDefaultActions(): void {
    // 注册所有AdsPower支持的Actions
    this.actions.set('click', ClickAction);
    this.actions.set('wait', WaitAction);
    this.actions.set('navigate', NavigateAction);
    this.actions.set('custom', CustomAction);
    this.actions.set('verify', VerifyAction);
    this.actions.set('fillForm', FillFormAction);
    this.actions.set('scroll', ScrollAction);
    this.actions.set('extract', ExtractAction);
    this.actions.set('retryBlock', RetryBlockAction);
  }

  getAction(actionName: string): any {
    const ActionClass = this.actions.get(actionName);
    
    if (!ActionClass) {
      throw new Error(`Unknown action: ${actionName} in AdsPower provider`);
    }

    return ActionClass;
  }

  hasAction(actionName: string): boolean {
    return this.actions.has(actionName);
  }

  /**
   * 注册自定义Action
   */
  registerAction(name: string, ActionClass: any): void {
    this.actions.set(name, ActionClass);
  }
}
