/**
 * Input validation utilities
 */
import { ZodError } from 'zod';
import { ReportInputSchema } from '../types/index.js';
import { ShaamFormatError } from './errors.js';
/**
 * Converts Zod errors to ValidationError format
 */
function convertZodErrorsToValidationErrors(zodError) {
    return zodError.issues.map((issue, index) => ({
        recordType: 'input',
        recordIndex: index,
        field: issue.path.join('.') || 'unknown',
        message: issue.message,
        value: issue.input,
    }));
}
/**
 * Validates report input data against the schema
 *
 * @param input - The input data to validate
 * @param mode - Validation mode ('fail-fast' or 'collect-all')
 * @returns Array of validation errors (empty if valid)
 */
export function validateInput(input, mode = 'fail-fast') {
    const errors = [];
    try {
        ReportInputSchema.parse(input);
    }
    catch (error) {
        if (error instanceof ZodError) {
            const validationErrors = convertZodErrorsToValidationErrors(error);
            if (mode === 'fail-fast') {
                throw new ShaamFormatError(`Validation failed: ${validationErrors[0]?.message || 'Unknown error'}`, validationErrors);
            }
            errors.push(...validationErrors);
        }
        else {
            // Handle non-Zod errors
            const unknownError = {
                recordType: 'unknown',
                recordIndex: 0,
                field: 'unknown',
                message: error instanceof Error ? error.message : 'Unknown validation error',
            };
            if (mode === 'fail-fast') {
                throw new ShaamFormatError('Validation failed', [unknownError]);
            }
            errors.push(unknownError);
        }
    }
    return errors;
}
//# sourceMappingURL=validate-input.js.map