"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;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpListCommand = void 0;
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const fs = __importStar(require("fs-extra"));
const path = __importStar(require("path"));
exports.OpListCommand = new commander_1.Command("op:list")
    .description("List pending and recent operations")
    .option("--all", "include applied and rolled-back operations")
    .option("--json", "output as JSON")
    .action(async (options) => {
    const opsDir = path.join(process.cwd(), ".mycontext", "operations");
    if (!(await fs.pathExists(opsDir))) {
        console.log(chalk_1.default.dim("\n  No operations recorded\n"));
        return;
    }
    const files = await fs.readdir(opsDir);
    const ops = [];
    for (const file of files) {
        if (!file.endsWith(".json"))
            continue;
        const record = await fs.readJson(path.join(opsDir, file));
        ops.push(record.operation || record);
    }
    ops.sort((a, b) => (b.timestamp || "").localeCompare(a.timestamp || ""));
    if (options.json) {
        console.log(JSON.stringify(ops, null, 2));
        return;
    }
    if (ops.length === 0) {
        console.log(chalk_1.default.dim("\n  No operations found\n"));
        return;
    }
    console.log(chalk_1.default.bold(`\n📋 Recent Operations (${ops.length})`));
    console.log(chalk_1.default.dim("─".repeat(60)));
    for (const op of ops) {
        const statusIcon = op.status === "applied"
            ? chalk_1.default.green("✓")
            : op.status === "failed"
                ? chalk_1.default.red("✗")
                : op.status === "rolled-back"
                    ? chalk_1.default.yellow("↩")
                    : chalk_1.default.dim("○");
        console.log(`  ${statusIcon} ${chalk_1.default.cyan(op.type)} ${chalk_1.default.dim(op.id?.substring(0, 30) || "?")}`);
        console.log(`     ${chalk_1.default.dim(op.description || "")}`);
        if (op.result?.error) {
            console.log(`     ${chalk_1.default.red(op.result.error)}`);
        }
    }
    console.log();
});
//# sourceMappingURL=op-list.js.map