/**
 * scaffold-screen-controller — validate.ts
 *
 * Pure Zod validation. No filesystem checks here (those happen inside execute
 * via parsePagespecsForSection, which tolerates a missing pagespecs/ dir).
 */

import { ScaffoldScreenControllerSpecSchema } from './types.js'
import type { ScaffoldScreenControllerSpec } from './types.js'

export interface ValidationResult {
  valid: boolean
  errors: string[]
  data?: ScaffoldScreenControllerSpec
}

export function validate(raw: unknown): ValidationResult {
  const parsed = ScaffoldScreenControllerSpecSchema.safeParse(raw)
  if (!parsed.success) {
    return {
      valid: false,
      errors: parsed.error.issues.map(i => `${i.path.join('.') || '<root>'}: ${i.message}`),
    }
  }
  return { valid: true, errors: [], data: parsed.data }
}
