import { StepId } from 'apps/companion/main/automation/domain/value-objects/StepId';
import type { PlaywrightAutomationAdapter } from 'core/automation/infrastructure//automation';
import type { AutomationResult } from 'apps/companion/main/automation/application/ports/AutomationResults';

export function assertAutoNavigationConfig(config: Record<string, unknown>): void {
  const skipFixtureNavigationFlag =
    (config as { __skipFixtureNavigation?: unknown }).__skipFixtureNavigation;
  if (skipFixtureNavigationFlag === true) {
    throw new Error('__skipFixtureNavigation is forbidden in auto-navigation suites');
  }
}

export async function executeStepWithAutoNavigationGuard(
  adapter: PlaywrightAutomationAdapter,
  step: number,
  config: Record<string, unknown>,
): Promise<AutomationResult> {
  assertAutoNavigationConfig(config);
  return adapter.executeStep(StepId.create(step), config);
}