"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.OpBatchCommand = void 0;
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const fs = __importStar(require("fs-extra"));
const OperationExecutor_1 = require("../services/OperationExecutor");
exports.OpBatchCommand = new commander_1.Command("op:batch")
    .description("Execute a batch of operations from a JSON file")
    .argument("<file>", "JSON file containing an array of operations")
    .action(async (filePath) => {
    if (!(await fs.pathExists(filePath))) {
        console.error(chalk_1.default.red(`File not found: ${filePath}`));
        process.exit(1);
    }
    const data = await fs.readJson(filePath);
    const ops = Array.isArray(data) ? data : data.operations || [];
    if (ops.length === 0) {
        console.error(chalk_1.default.yellow("No operations found in file"));
        process.exit(0);
    }
    console.log(chalk_1.default.bold(`\n📦 Executing batch: ${ops.length} operations`));
    console.log(chalk_1.default.dim("─".repeat(50)));
    const executor = new OperationExecutor_1.OperationExecutor();
    const results = await executor.executeBatch(ops);
    let passed = 0;
    let failed = 0;
    results.forEach((r, i) => {
        const opDef = ops[i];
        if (r.success) {
            passed++;
            console.log(`  ${chalk_1.default.green("✓")} ${opDef?.description || opDef?.type || "op"}`);
        }
        else {
            failed++;
            console.log(`  ${chalk_1.default.red("✗")} ${opDef?.description || opDef?.type || "op"} — ${r.error}`);
        }
    });
    console.log(chalk_1.default.dim("─".repeat(50)));
    console.log(`  ${chalk_1.default.green(`${passed} passed`)}${failed > 0 ? ` · ${chalk_1.default.red(`${failed} failed`)}` : ""}`);
    console.log();
});
//# sourceMappingURL=op-batch.js.map