/**
 * audit-dev-tests — types.ts
 *
 * Compares BA Acceptance Criteria (declared in use-case.md) against the
 * generated xUnit `[Trait("AC","…")]` Facts. Emits DEV-TEST-001..003 findings.
 */

import { z } from 'zod'

export const AuditDevTestsSpecSchema = z.object({
  /** Absolute path to the BA module folder (e.g. `.smartstack/ba/CRM/PIPELINE`). */
  moduleDir: z.string().min(1),
  /** Absolute path to the .NET solution root (where `Tests/` lives). */
  projectPath: z.string().min(1),
})

export type AuditDevTestsSpec = z.infer<typeof AuditDevTestsSpecSchema>

export const SeverityEnum = z.enum(['err', 'warn', 'ok'])
export type Severity = z.infer<typeof SeverityEnum>

export const FindingSchema = z.object({
  /** Rule code, e.g. `DEV-TEST-001`. */
  rule: z.string().regex(/^DEV-TEST-\d{3}$/),
  severity: SeverityEnum,
  /** Short single-line message. */
  message: z.string().min(1),
  /** AC ids or file paths involved in this finding. */
  refs: z.array(z.string()).default([]),
  /** Free-form fix suggestion. */
  fix: z.string().optional(),
})

export type Finding = z.infer<typeof FindingSchema>

export const AuditReportSchema = z.object({
  success: z.boolean(),
  error: z.string().optional(),
  /** Total BA AC count scanned. */
  baAcCount: z.number(),
  /** Total `[Trait("AC","…")]` count scanned. */
  testTraitCount: z.number(),
  /** Total `// TODO[AC-` markers found. */
  todoMarkerCount: z.number(),
  findings: z.array(FindingSchema),
})

export type AuditReport = z.infer<typeof AuditReportSchema>
