"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.generator = exports.generatorId = void 0;
const path = __importStar(require("node:path"));
const Generator = __importStar(require("@postxl/generator"));
const generator_1 = require("@postxl/generator");
const backend_actions_1 = require("../backend-actions");
const backend_core_1 = require("../backend-core");
const backend_upload_1 = require("../backend-upload");
const backend_view_1 = require("../backend-view");
const decoders_1 = require("../decoders");
const types_1 = require("../types");
const excel_io_service_generator_1 = require("./generators/excel-io-service.generator");
exports.generatorId = Generator.toGeneratorInterfaceId('backend-excel-io');
exports.generator = {
    id: exports.generatorId,
    requires: [
        backend_core_1.backendGeneratorId,
        backend_actions_1.backendActionsGeneratorId,
        backend_view_1.backendViewGeneratorId,
        backend_upload_1.backendUploadGeneratorId,
        decoders_1.decodersGeneratorId,
        types_1.typesGeneratorId,
    ],
    register: (context) => {
        const module = {
            name: Generator.toClassName('ExcelIoModule'),
            location: Generator.toBackendModuleLocation('@excel-io/excel-io.module'),
        };
        const excelIoModule = {
            name: Generator.toBackendModuleName('excel-io'),
            moduleClass: module,
            apiModuleRegistration: {
                code: (0, generator_1.ts)('ExcelIoModule'),
            },
        };
        context.backend.modules.push(excelIoModule);
        const service = {
            name: Generator.toClassName('ExcelIoService'),
            location: Generator.toBackendModuleLocation('@excel-io/excel-io.service'),
        };
        const controller = {
            name: Generator.toClassName('ExcelIoController'),
            location: Generator.toBackendModuleLocation('@excel-io/excel-io.controller'),
        };
        const excelIo = { module, service, controller };
        return { ...context, excelIo };
    },
    generate: async (context) => {
        const vfsSrc = new Generator.VirtualFileSystem();
        await vfsSrc.loadFile({
            diskPath: path.resolve(__dirname, './template/excel-io.controller.ts'),
            targetPath: Generator.toLocalFile(context.excelIo.controller),
        });
        await vfsSrc.loadFile({
            diskPath: path.resolve(__dirname, './template/excel-io.module.ts'),
            targetPath: Generator.toLocalFile(context.excelIo.module),
        });
        await vfsSrc.loadFile({
            diskPath: path.resolve(__dirname, './template/README.md'),
            targetPath: 'README.md',
        });
        vfsSrc.write(Generator.toLocalFile(context.excelIo.service), (0, excel_io_service_generator_1.generateExcelIoService)(context));
        vfsSrc.write('index.ts', `export { ExcelIoModule } from './excel-io.module'
export { ExcelIoService } from './excel-io.service'
export { ExcelIoController } from './excel-io.controller'
`);
        const vfs = new Generator.VirtualFileSystem();
        vfs.insertFromVfs({ targetPath: 'src', vfs: vfsSrc });
        vfs.write('/tsconfig.lib.json', Generator.generateTsConfig('excel-io'));
        context.vfs.insertFromVfs({ targetPath: 'backend/libs/excel-io', vfs });
        return context;
    },
};
//# sourceMappingURL=excel-io.generator.js.map