"use strict";
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.loadCellState = loadCellState;
exports.saveCellState = saveCellState;
exports.markSetupCompleted = markSetupCompleted;
exports.markFirstScan = markFirstScan;
exports.markFirstContext = markFirstContext;
exports.markBridgeStarted = markBridgeStarted;
exports.markDoctorRun = markDoctorRun;
const fs = __importStar(require("fs"));
const os = __importStar(require("os"));
const path = __importStar(require("path"));
const STATE_FILE = path.join(os.homedir(), '.fivo', 'cell', 'cell-state.json');
function loadCellState() {
    try {
        if (!fs.existsSync(STATE_FILE))
            return {};
        return JSON.parse(fs.readFileSync(STATE_FILE, 'utf8'));
    }
    catch {
        return {};
    }
}
function saveCellState(update) {
    try {
        const dir = path.dirname(STATE_FILE);
        if (!fs.existsSync(dir))
            fs.mkdirSync(dir, { recursive: true });
        const current = loadCellState();
        const merged = { ...current, ...update };
        fs.writeFileSync(STATE_FILE, JSON.stringify(merged, null, 2), 'utf8');
    }
    catch { }
}
function markSetupCompleted() {
    saveCellState({ setup_completed: new Date().toISOString() });
}
function markFirstScan() {
    const state = loadCellState();
    if (!state.first_scan_at) {
        saveCellState({ first_scan_at: new Date().toISOString() });
    }
    saveCellState({ last_scan_at: new Date().toISOString() });
}
function markFirstContext() {
    const state = loadCellState();
    if (!state.first_context_at) {
        saveCellState({ first_context_at: new Date().toISOString() });
    }
    saveCellState({ last_context_at: new Date().toISOString() });
}
function markBridgeStarted() {
    const state = loadCellState();
    if (!state.bridge_started_at) {
        saveCellState({ bridge_started_at: new Date().toISOString() });
    }
}
function markDoctorRun() {
    saveCellState({ doctor_run_at: new Date().toISOString() });
}
//# sourceMappingURL=cell-state.js.map