/**
 * validate-conventions/types.ts — CLI args + report shape for the conventions
 * audit of a SmartStack project.
 */
import { z } from 'zod';

export const CheckNames = [
  'namespaces',
  'entities',
  'controllers',
  'all',
] as const;

export type CheckName = (typeof CheckNames)[number];

export const ValidateConventionsArgsSchema = z.object({
  /** Absolute path of the SmartStack project to audit (defaults to cwd). */
  projectPath: z.string().optional(),
  /**
   * Which checks to run. Defaults to ['all']. Each check scans a different
   * aspect of the project and produces findings in the report.
   */
  checks: z
    .array(z.enum(CheckNames))
    .default(['all']),
  /**
   * Override the expected base namespace (e.g. "Acme.Corp"). When omitted,
   * the CLI auto-detects from .csproj files.
   */
  baseNamespace: z.string().optional(),
});

export type ValidateConventionsArgs = z.infer<typeof ValidateConventionsArgsSchema>;

// ─── Finding ──────────────────────────────────────────────────────────────

export type Severity = 'error' | 'warning' | 'info';

export type Category = 'namespaces' | 'entities' | 'controllers';

export interface Finding {
  severity: Severity;
  category: Category;
  message: string;
  file?: string;
  suggestion?: string;
}

// ─── Report ───────────────────────────────────────────────────────────────

export interface ConventionsReport {
  /** Absolute project path that was scanned. */
  projectPath: string;
  /** Detected SmartStack layer paths. */
  structure: {
    domain: string | null;
    application: string | null;
    infrastructure: string | null;
    api: string | null;
    web: string | null;
  };
  /** Checks that were actually executed (after 'all' expansion). */
  checksRun: Category[];
  /** Total number of files inspected across all checks. */
  filesInspected: number;
  /** Every finding produced by the checks. */
  findings: Finding[];
  /** Counts per severity. */
  counts: {
    errors: number;
    warnings: number;
    infos: number;
  };
  /** Counts per category. */
  byCategory: Record<Category, number>;
}

// ─── Output envelope ──────────────────────────────────────────────────────

export interface ValidateConventionsOutput {
  success: boolean;
  command: 'validate-conventions';
  data?: {
    valid: boolean;
    summary: string;
  };
  report: ConventionsReport | null;
  errors: string[];
  warnings: string[];
  nextSteps: string[];
}
