// engine/ide-config/validator.ts — Validate generated IDE configs (SPEC-080 AC-11)
import { isBinaryInPath } from './detector.js';
/**
 * Validate JSON syntax of the generated content.
 */
function validateJsonSyntax(config, ide) {
    if (ide.configFormat === 'lua') {
        return null; // Lua is not JSON
    }
    try {
        JSON.parse(config.content);
        return null;
    }
    catch (err) {
        /* v8 ignore next 1 */
        const message = err instanceof Error ? err.message : 'Unknown parse error';
        return {
            field: 'content',
            message: `Invalid JSON syntax: ${message}`,
            suggestion: 'Check for trailing commas or missing quotes in the generated config.',
        };
    }
}
/**
 * Validate that npx/npx.cmd is available.
 */
function validateCommandAvailable() {
    /* v8 ignore next 1 */
    const cmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';
    if (!isBinaryInPath(cmd)) {
        return {
            field: 'command',
            message: `"${cmd}" not found in PATH`,
            suggestion: 'Install Node.js (https://nodejs.org) to get npx.',
        };
    }
    return null;
}
/**
 * Validate a generated IDE configuration.
 * Returns an array of validation errors (empty = valid).
 */
export function validateConfig(config, ide) {
    const errors = [];
    const jsonError = validateJsonSyntax(config, ide);
    if (jsonError) {
        errors.push(jsonError);
    }
    const cmdError = validateCommandAvailable();
    if (cmdError) {
        errors.push(cmdError);
    }
    return errors;
}
//# sourceMappingURL=validator.js.map