"use strict";
/**
 * 🔍 faf validate - Validation Command
 * Validates .faf files against schema with detailed feedback
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateFafFile = validateFafFile;
const colors_1 = require("../fix-once/colors");
const fs_1 = require("fs");
const yaml_1 = require("../fix-once/yaml");
const faf_schema_1 = require("../schema/faf-schema");
const file_utils_1 = require("../utils/file-utils");
const technical_credit_1 = require("../utils/technical-credit");
async function validateFafFile(file, options = {}) {
    try {
        const fafPath = file || (await (0, file_utils_1.findFafFile)());
        if (!fafPath) {
            console.log(colors_1.chalk.red("❌ No .faf file found"));
            console.log(colors_1.chalk.yellow('💡 Run "faf init" to create one'));
            process.exit(1);
        }
        console.log(colors_1.chalk.blue(`🔍 Validating: ${fafPath}`));
        // Read and parse .faf file
        const content = await fs_1.promises.readFile(fafPath, "utf-8");
        const fafData = (0, yaml_1.parse)(content);
        // Validate against schema
        const validation = (0, faf_schema_1.validateSchema)(fafData, options.schema || "latest");
        if (validation.valid) {
            console.log(colors_1.chalk.green("☑️ Valid .faf file"));
            // Award technical credit for successful validation
            await (0, technical_credit_1.autoAwardCredit)('validation_passed', fafPath);
            if (options.verbose) {
                console.log(colors_1.chalk.gray("📊 Validation Details:"));
                console.log(colors_1.chalk.gray(`   Schema Version: ${validation.schemaVersion}`));
                console.log(colors_1.chalk.gray(`   Format Version: ${fafData.faf_version || "unknown"}`));
                console.log(colors_1.chalk.gray(`   Total Sections: ${validation.sectionsFound}`));
                console.log(colors_1.chalk.gray(`   Required Fields: ${validation.requiredFieldsFound}/${validation.requiredFieldsTotal}`));
            }
        }
        else {
            console.log(colors_1.chalk.red("❌ Invalid .faf file"));
            console.log(colors_1.chalk.red("🚨 Errors found:"));
            validation.errors.forEach((error, index) => {
                console.log(colors_1.chalk.red(`   ${index + 1}. ${error.message}`));
                if (error.path) {
                    console.log(colors_1.chalk.gray(`      Path: ${error.path}`));
                }
            });
            if (validation.warnings.length > 0) {
                console.log(colors_1.chalk.yellow("⚠️  Warnings:"));
                validation.warnings.forEach((warning, index) => {
                    console.log(colors_1.chalk.yellow(`   ${index + 1}. ${warning.message}`));
                });
            }
            process.exit(1);
        }
    }
    catch (error) {
        console.log(colors_1.chalk.red("💥 Validation failed:"));
        console.log(colors_1.chalk.red(error instanceof Error ? error.message : String(error)));
        process.exit(1);
    }
}
//# sourceMappingURL=validate.js.map