/**
 * cli:validate-page — types.ts
 *
 * Per-page deterministic validator. Runs eight blocking rules on a single
 * generated page .tsx file. Used by the per-page audit-or-regenerate loop
 * in ba-develop Phase 3a as the gate between scaffold-component
 * invocations.
 *
 * Read-only: never writes files. The orchestrator is responsible for retries
 * and aborts based on the report.
 */
import { z } from 'zod'

export const ValidatePageInputSchema = z.object({
  /** Web root, e.g. `<projectRoot>/web/<app>-web` (parent of `src/`). */
  projectPath: z.string().min(1),
  /**
   * Page file to validate. Either an absolute path or a path relative to
   * `projectPath`. Must end in `.tsx`.
   */
  pageFile: z.string().min(1),
})

export type ValidatePageInput = z.infer<typeof ValidatePageInputSchema>

export type Severity = 'err' | 'warn'

export interface Violation {
  /** Rule id, e.g. 'imports-resolve'. Stable across releases. */
  rule: string
  severity: Severity
  /** 1-based line number when the rule can pinpoint one. */
  line?: number
  /** Specific, actionable message including the offending value. */
  message: string
  /** Deterministic remediation hint — empty when fix requires judgement. */
  suggestedFix?: string
}

export interface ValidatePageReport {
  /** Absolute path to the page that was validated. */
  pageFile: string
  /** Module derived from the path, e.g. 'crm'. Null if path is non-standard. */
  module: string | null
  /** Entity derived from the filename, e.g. 'Contact'. Null if filename is non-standard. */
  entity: string | null
  /** View derived from the filename, e.g. 'list' | 'detail' | 'form' | 'dashboard' | 'create' | 'edit'. */
  view: string | null
  /** Ordered violations — caller renders them as-is. */
  violations: Violation[]
}

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