"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.OpCreateFileCommand = 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");
const core_1 = require("@myycontext/core");
exports.OpCreateFileCommand = new commander_1.Command("op:create-file")
    .description("Create a new file with content")
    .argument("<path>", "file path")
    .argument("<content>", "file content (use --file to read from file)")
    .option("--file <filepath>", "read content from a file instead of argument")
    .option("--overwrite", "overwrite existing file")
    .action(async (filePath, content, options) => {
    const executor = new OperationExecutor_1.OperationExecutor();
    const finalContent = options.file
        ? await fs.readFile(options.file, "utf-8")
        : content;
    const op = (0, core_1.createOperation)("create-file", `Create file: ${filePath}`, {
        path: filePath,
        content: finalContent,
        overwrite: !!options.overwrite,
    });
    const result = await executor.execute(op);
    if (result.success) {
        console.log(chalk_1.default.green(`\n  ✓ Created: ${result.outputPath}\n`));
    }
    else {
        console.error(chalk_1.default.red(`\n  ✗ Failed: ${result.error}\n`));
        process.exit(1);
    }
});
//# sourceMappingURL=op-create-file.js.map