"use strict";
/**
 * ModelStandardsUtility
 *
 * Utility functions for validating models against coding standards
 * using the ReelCode package functionality
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateModelStandards = validateModelStandards;
exports.applyModelStandards = applyModelStandards;
exports.generateModelStandardsConfig = generateModelStandardsConfig;
const reelcode_1 = require("@bluefly/reelcode");
// Path to the model standards file
const path_1 = __importDefault(require("path"));
// Determine the path to the model standards file
// In a production environment, we'd want to use a relative path
// This is just for development purposes
const MODEL_STANDARDS_PATH = path_1.default.resolve(__dirname, './model-standards.yml');
// Convert bfui model types to ReelCode BaseModel
function convertToBaseModel(model) {
    if (!model)
        return null;
    // BaseModel has the same properties as our model types, so we can just cast it
    return model;
}
/**
 * Validates model configuration against predefined standards
 *
 * @param model Model data to validate
 * @returns Validation result
 */
async function validateModelStandards(model) {
    if (!model) {
        return {
            valid: true,
            errors: [],
            warnings: []
        };
    }
    try {
        // Convert the model to BaseModel format
        const baseModel = convertToBaseModel(model);
        // Use the validateModel function from ReelCode
        const result = await (0, reelcode_1.validateModel)(baseModel, MODEL_STANDARDS_PATH);
        return result;
    }
    catch (error) {
        console.error('Error validating model standards:', error);
        // Fallback to a simple validation result
        return {
            valid: false,
            errors: [{
                    rule: 'validation:error',
                    message: `Error validating model: ${error instanceof Error ? error.message : 'Unknown error'}`
                }],
            warnings: []
        };
    }
}
/**
 * Applies model standards to a model configuration
 *
 * This function tries to automatically fix model configuration issues
 * according to predefined standards
 *
 * @param model Model data to fix
 * @returns Fixed model data
 */
async function applyModelStandards(model) {
    if (!model)
        return model;
    try {
        // Convert the model to BaseModel format
        const baseModel = convertToBaseModel(model);
        // Use the applyModelConfigStandards function from ReelCode
        const fixedBaseModel = await (0, reelcode_1.applyModelConfigStandards)(baseModel, MODEL_STANDARDS_PATH);
        // Convert back to the original type
        return fixedBaseModel;
    }
    catch (error) {
        console.error('Error applying model standards:', error);
        // If there's an error, return the original model
        return model;
    }
}
/**
 * Generates model standards configuration for AI assistants
 *
 * @param projectId - ID of the project
 * @returns Configuration object that could be used by AI assistants
 */
async function generateModelStandardsConfig(projectId) {
    try {
        // Create a standards manager instance
        const standardsManager = new reelcode_1.StandardsManager({
            projectId,
            configPath: MODEL_STANDARDS_PATH
        });
        // Initialize the standards manager
        await standardsManager.initialize();
        // Return the standards configuration
        return standardsManager.getStandards();
    }
    catch (error) {
        console.error('Error generating model standards configuration:', error);
        // Return a basic configuration if there's an error
        return {
            projectId,
            name: "Model Registry Standards",
            version: "1.0.0",
            rules: {}
        };
    }
}
//# sourceMappingURL=ModelStandardsUtility.js.map