/**
 * cli:aggregate-component-registry — types.ts
 *
 * Zod input schema for the deterministic aggregator that consolidates
 * per-module `{module}Registry.ts` files into a single
 * `componentRegistry.generated.ts` import-side-effect entry point.
 *
 * Replaces the legacy "sub-agent hand-writes the file" 3c step in the
 * Frontend phase of ba-develop. Hand-writing produced phantom
 * imports (Vite fails at launch) and key collisions across modules — both
 * caught here at write time instead of at runtime.
 */
import { z } from 'zod'

export const AggregateComponentRegistryInputSchema = z.object({
  /** Web root, e.g. `<projectRoot>/web/<app>-web` (parent of `src/`). */
  projectPath: z.string().min(1),
  /**
   * Optional list of modules to include. When omitted, the CLI auto-discovers
   * every `src/extensions/*Registry.ts` (excluding the generated aggregator
   * itself). When provided, it MUST be exhaustive — any extra `*Registry.ts`
   * on disk that is not listed here is reported as a warning (likely orphan).
   */
  modules: z.array(z.string().min(1)).optional(),
  /**
   * Override the output file. Defaults to
   * `src/extensions/componentRegistry.generated.ts`. Relative to projectPath.
   */
  outFile: z.string().optional(),
  /**
   * Glob patterns (relative to `src/extensions/`) to exclude from
   * auto-discovery. Useful for legacy registry shells we don't want in the
   * aggregated output.
   */
  exclude: z.array(z.string()).default([]),
})

export type AggregateComponentRegistryInput = z.infer<typeof AggregateComponentRegistryInputSchema>

export interface ParsedRegistry {
  /** Filename of the per-module registry (e.g. `budgetsRegistry.ts`). */
  file: string
  /** Module name extracted from the filename (`budgets` for `budgetsRegistry.ts`). */
  module: string
  /** ComponentKeys registered by this module. */
  keys: string[]
  /** Lazy import paths (the `import('@/pages/...')` strings). */
  lazyImports: string[]
}

export interface ResolvedImport {
  /** Module that emitted this lazy import. */
  module: string
  /** The path string inside `import('...')`, verbatim. */
  importPath: string
  /** Resolved on-disk file (absolute) or `null` if the path doesn't resolve. */
  resolved: string | null
}

export interface GeneratedFile {
  path: string
  content: string
}

export interface ValidationResult {
  valid: boolean
  errors: string[]
  warnings: string[]
}
