/**
 * Types related to automated test code generation from the editor data.
 * These extend the base test model stored in data/testcases.json.
 */

// ──────────────────────────────────────────────────────────────
// Core Generation Types
// ──────────────────────────────────────────────────────────────

export interface CodeStep {
  /** Human-readable step name that will become the title of `test.step()` */
  stepName: string;

  /** Key that maps to an entry in the Action Catalog (e.g. "navigate_to_downloads_portal") */
  actionKey: string;

  /** Optional parameters to be substituted into the template */
  params?: Record<string, any>;
}

export interface VerifiedSnippet {
  /** The step name this snippet corresponds to */
  stepName: string;

  /** Raw Playwright / MCP code that was manually validated */
  code: string;
}

export interface AutomatedTestExtension {
  /**
   * When true, this test is considered ready for full automated code generation.
   * This is stricter than `status === "automated"`.
   */
  fullyAutomated?: boolean;

  /**
   * Ordered list of executable steps.
   * Each step will be turned into a `await test.step(...)` block.
   */
  codeSteps?: CodeStep[];

  /** Free-form notes for the developer or LLM when generating code */
  implementationNotes?: string;

  /**
   * Manually verified code snippets.
   * These take precedence over the Action Catalog when present.
   */
  verifiedSnippets?: VerifiedSnippet[];
}

// ──────────────────────────────────────────────────────────────
// Combined Type used by the Generator
// ──────────────────────────────────────────────────────────────

export interface EnrichedTestForGeneration {
  // Base fields (from testcases.json)
  id: string;
  group: string;
  module: 'core' | 'pbx';
  action: 'check' | 'write';
  description: string;
  status: 'automated' | 'partial' | 'manual';
  file: string;

  // Existing rich metadata
  steps?: string[];
  automatable?: string[];
  notYet?: string[];
  dependencies?: Array<{ label: string; value: string }>;

  // New fields for code generation
  fullyAutomated?: boolean;
  codeSteps?: CodeStep[];
  implementationNotes?: string;
  verifiedSnippets?: VerifiedSnippet[];
}

/**
 * Type used when the generator receives data (after merging).
 */
export type TestForCodeGeneration = EnrichedTestForGeneration;
