"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.importCommand = void 0;
const fs_1 = __importDefault(require("fs"));
const database_1 = require("../database");
const logger_1 = __importDefault(require("../logger"));
const telemetry_1 = __importDefault(require("../telemetry"));
function importCommand(program) {
    program
        .command('import <file>')
        .description('Import an eval record from a JSON file')
        .action(async (file) => {
        try {
            const fileContent = fs_1.default.readFileSync(file, 'utf-8');
            const evalData = JSON.parse(fileContent);
            const db = (0, database_1.getDb)();
            await db
                .insert(database_1.evals)
                .values({
                id: evalData.id,
                createdAt: evalData.createdAt,
                description: evalData.description,
                results: evalData.results,
                config: evalData.config,
            })
                .run();
            logger_1.default.info(`Eval with ID ${evalData.id} has been successfully imported.`);
            telemetry_1.default.record('command_used', {
                name: 'import',
                evalId: evalData.id,
            });
            await telemetry_1.default.send();
        }
        catch (error) {
            logger_1.default.error(`Failed to import eval: ${error}`);
            process.exit(1);
        }
    });
}
exports.importCommand = importCommand;
//# sourceMappingURL=import.js.map