import { PrOptionsSchema } from './types.js'

export interface ValidationResult {
  valid: boolean
  data?: Record<string, unknown>
  blockers: string[]
  warnings: string[]
}

export function validate(spec: unknown): ValidationResult {
  const blockers: string[] = []
  const warnings: string[] = []

  try {
    const data = PrOptionsSchema.parse(spec)
    return {
      valid: blockers.length === 0,
      data,
      blockers,
      warnings,
    }
  } catch (err) {
    const message = err instanceof Error ? err.message : String(err)
    blockers.push(`Invalid spec: ${message}`)
    return { valid: false, blockers, warnings }
  }
}
