import { MergeOptionsSchema } 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 parsed = MergeOptionsSchema.parse(spec)

    // Mutual exclusivity check
    if (parsed.squash && parsed.merge) {
      blockers.push('squash and merge are mutually exclusive')
    }

    return {
      valid: blockers.length === 0,
      data: parsed as Record<string, unknown>,
      blockers,
      warnings,
    }
  } catch (err) {
    const message = err instanceof Error ? err.message : String(err)
    blockers.push(`Invalid spec: ${message}`)
    return { valid: false, blockers, warnings }
  }
}
