/**
 * cli:scaffold-business — validate.ts
 */
import { ScaffoldBusinessInputSchema, type ScaffoldBusinessInput, type ValidationResult } from './types.js'

export function validateStructure(raw: unknown): ValidationResult {
  const result = ScaffoldBusinessInputSchema.safeParse(raw)
  if (result.success) return { valid: true, errors: [], warnings: [] }
  return { valid: false, errors: result.error.issues.map(i => `[${i.path.join('.')}] ${i.message}`), warnings: [] }
}

export function validateBusinessRules(spec: ScaffoldBusinessInput): ValidationResult {
  const warnings: string[] = []
  if (spec.businessRules.length === 0) {
    warnings.push('No business rules provided — validator will only have basic field validation')
  }
  return { valid: true, errors: [], warnings }
}

export function validate(raw: unknown): ValidationResult {
  const structural = validateStructure(raw)
  if (!structural.valid) return structural
  return validateBusinessRules(raw as ScaffoldBusinessInput)
}
