import { EntityAuditSpecSchema, type EntityAuditSpec } from './types.js'

export interface ValidateResult {
  valid: boolean
  errors: string[]
  spec: EntityAuditSpec | null
}

export function validate(raw: unknown): ValidateResult {
  const r = EntityAuditSpecSchema.safeParse(raw)
  if (!r.success) {
    return { valid: false, errors: r.error.issues.map((i) => `[${i.path.join('.')}] ${i.message}`), spec: null }
  }
  return { valid: true, errors: [], spec: r.data }
}
