/**
 * sync CLI validate — Pure validation, no I/O
 */

import { SyncSpecSchema, type SyncSpec } from './types.js';

export interface ValidationResult {
  valid: boolean;
  data?: SyncSpec;
  blockers: string[];
  warnings: string[];
}

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

  let data: SyncSpec | undefined;
  try {
    data = SyncSpecSchema.parse(spec);
  } catch (err: unknown) {
    const e = err as any;
    if (e.errors) {
      for (const error of e.errors) {
        blockers.push(`${error.path?.join('.')}: ${error.message}`);
      }
    } else {
      blockers.push(`Spec parse failed: ${(err as Error).message}`);
    }
    return { valid: false, blockers, warnings };
  }

  return { valid: blockers.length === 0, data, blockers, warnings };
}
