"use strict";
/**
 * BIG ORANGE 🍊 - Output Handler
 * Pushes comparison results to Big🍊 web visualization
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.pushToBigO = pushToBigO;
exports.fetchSession = fetchSession;
const promises_1 = require("fs/promises");
const path_1 = require("path");
/**
 * Push comparison results to Big🍊
 * @param results - Comparison results to store
 * @returns URL to view results
 */
async function pushToBigO(results) {
    const sessionId = results.sessionId;
    // For now: Write to file system
    // Later: POST to API endpoint
    const dataDir = process.env.BIGO_DATA_DIR || '/tmp/big-orange-sessions';
    const sessionFile = (0, path_1.join)(dataDir, `${sessionId}.json`);
    try {
        // Ensure directory exists
        await (0, promises_1.mkdir)(dataDir, { recursive: true });
        // Write session data
        await (0, promises_1.writeFile)(sessionFile, JSON.stringify(results, null, 2), 'utf-8');
        console.log(`✓ Session saved: ${sessionFile}`);
    }
    catch (error) {
        console.error('Failed to save session:', error);
        throw error;
    }
    // Return URL to Big🍊
    const baseUrl = process.env.BIGO_URL || 'https://fafdev.tools';
    return `${baseUrl}/BigO?session=${sessionId}`;
}
/**
 * Fetch session results (for Big🍊 web app)
 * @param sessionId - Session ID to fetch
 * @returns Comparison results
 */
async function fetchSession(sessionId) {
    const dataDir = process.env.BIGO_DATA_DIR || '/tmp/big-orange-sessions';
    const sessionFile = (0, path_1.join)(dataDir, `${sessionId}.json`);
    try {
        const { readFile } = await Promise.resolve().then(() => __importStar(require('fs/promises')));
        const data = await readFile(sessionFile, 'utf-8');
        return JSON.parse(data);
    }
    catch (error) {
        console.error(`Session not found: ${sessionId}`);
        return null;
    }
}
//# sourceMappingURL=bigo-push.js.map