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

    // Validate staleDays if provided
    if (parsed.staleDays !== undefined && parsed.staleDays <= 0) {
      blockers.push('staleDays must be a positive integer')
    }

    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 }
  }
}
