/**
 * cli:cross-validate-stack — types.ts
 * Source de verite unique : Zod schemas + types inferes
 * Contrat JSON pour la validation cross-stack backend .NET / frontend React
 */
import { z } from 'zod'

// ─── Input : parametres de la validation ───
export const CrossValidateInputSchema = z.object({
  specs: z.string().min(1, 'specs directory is required'),
  src: z.string().min(1, 'src directory is required'),
})

export type CrossValidateInput = z.infer<typeof CrossValidateInputSchema>

// ─── Check IDs ───
export const CHECK_IDS = [
  'routes-have-endpoints',
  'endpoints-are-consumed',
  'permissions-aligned',
  'resources-have-screens',
  'rbac-consistent',
] as const

export type CheckId = (typeof CHECK_IDS)[number]

// ─── Statuts possibles pour un check ───
export const CHECK_STATUSES = ['ok', 'error', 'warning', 'skipped'] as const

// ─── Resultat individuel d'un check ───
export const CheckResultSchema = z.object({
  id: z.enum(CHECK_IDS),
  status: z.enum(CHECK_STATUSES),
  count: z.number().int().optional(),
  details: z.string().optional(),
})

export type CheckResult = z.infer<typeof CheckResultSchema>

// ─── Rapport complet ───
export const CrossValidateReportSchema = z.object({
  timestamp: z.string(),
  checks: z.array(CheckResultSchema),
  errors: z.number().int().min(0),
  warnings: z.number().int().min(0),
})

export type CrossValidateReport = z.infer<typeof CrossValidateReportSchema>

// ─── Resultat de validation d'input ───
export interface ValidationResult {
  valid: boolean
  data?: CrossValidateInput
  blockers: string[]
  warnings: string[]
}

// ─── Structures internes pour les specs JSON ───
export interface SpecEndpoint {
  verb: string
  route: string
  paginated?: boolean
  requestDto?: string
  responseDto?: string
}

export interface SpecEndpoints {
  endpoints: SpecEndpoint[]
}

export interface SpecMeta {
  app: string
  module: string
  section: string
  resource: string
  description: string
  version: string
  tenantMode?: string
  tablePrefix?: string
}

export interface SpecPermissions {
  class: string
  permissions: string[]
}
