"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenerateMessages = void 0;
const path = require("path");
const yok_1 = require("../yok");
class GenerateMessages {
    constructor($fs, $messageContractGenerator, $options) {
        this.$fs = $fs;
        this.$messageContractGenerator = $messageContractGenerator;
        this.$options = $options;
        this.allowedParameters = [];
    }
    async execute(args) {
        const result = await this.$messageContractGenerator.generate();
        const innerMessagesDirectory = path.join(__dirname, "../messages");
        const outerMessagesDirectory = path.join(__dirname, "../..");
        let interfaceFilePath;
        let implementationFilePath;
        if (this.$options.default) {
            interfaceFilePath = path.join(innerMessagesDirectory, GenerateMessages.MESSAGES_DEFINITIONS_FILE_NAME);
            implementationFilePath = path.join(innerMessagesDirectory, GenerateMessages.MESSAGES_IMPLEMENTATION_FILE_NAME);
        }
        else {
            interfaceFilePath = path.join(outerMessagesDirectory, GenerateMessages.MESSAGES_DEFINITIONS_FILE_NAME);
            implementationFilePath = path.join(outerMessagesDirectory, GenerateMessages.MESSAGES_IMPLEMENTATION_FILE_NAME);
        }
        this.$fs.writeFile(interfaceFilePath, result.interfaceFile);
        this.$fs.writeFile(implementationFilePath, result.implementationFile);
    }
}
exports.GenerateMessages = GenerateMessages;
GenerateMessages.MESSAGES_DEFINITIONS_FILE_NAME = "messages.interface.d.ts";
GenerateMessages.MESSAGES_IMPLEMENTATION_FILE_NAME = "messages.ts";
yok_1.injector.registerCommand("dev-generate-messages", GenerateMessages);
