/**
 * Functions that declare exports for generated modules in `src/index.ts`.
 * Updates the barrel so consumers can import aggregate, model, response,
 * mapper, mock data, module, and DTO from the index.
 */
import { join } from 'node:path';
import { IndentationText, Project, QuoteKind } from 'ts-morph';
import { NewLineKind } from 'typescript';
import { API_CONTAINER, APP_CONTAINER } from '../../domain/config.js';
import { toCamelCase, toKebabCase, toPascalCase } from '../../utils/string-utils.js';
import { ExportDriver } from './drivers/export.driver.js';
function createProject(srcDirectory) {
    return new Project({
        manipulationSettings: {
            indentationText: IndentationText.TwoSpaces,
            newLineKind: NewLineKind.LineFeed,
            quoteKind: QuoteKind.Single,
            usePrefixAndSuffixTextForRename: false,
            useTrailingCommas: false,
        },
        tsConfigFilePath: join(process.cwd(), srcDirectory, '..', 'tsconfig.json'),
    });
}
// eslint-disable-next-line max-params
export function declareBackAppItemsExports(project, srcDirectory, boundedContextName, moduleName, aggregateName, excluded = []) {
    if (excluded.includes('src/@app/**'))
        return;
    const bcKebab = toKebabCase(boundedContextName);
    const modKebab = toKebabCase(moduleName);
    const bcPascal = toPascalCase(boundedContextName);
    const modPascal = toPascalCase(moduleName);
    const bcCamel = toCamelCase(boundedContextName);
    const sourceFile = project.addSourceFileAtPath(join(process.cwd(), srcDirectory, 'index.ts'));
    const appBase = `${APP_CONTAINER}/${bcKebab}/${modKebab}`;
    if (!excluded.includes(`src/${appBase}/domain/${bcKebab}-${modKebab}.aggregate.ts`)) {
        ExportDriver.createExportItems(sourceFile, `./${appBase}/domain/${bcKebab}-${modKebab}.aggregate`, [aggregateName]);
    }
    if (!excluded.includes(`src/${appBase}/infrastructure/sequelize/${bcKebab}-sequelize-${modKebab}.model.ts`)) {
        ExportDriver.createExportItems(sourceFile, `./${APP_CONTAINER}/${bcKebab}/${modKebab}`, [`${bcPascal}${modPascal}Model`]);
    }
    if (!excluded.includes(`src/${appBase}/domain/${bcKebab}-${modKebab}.response.ts`)) {
        ExportDriver.createExportItems(sourceFile, `./${appBase}/domain/${bcKebab}-${modKebab}.response`, [`${bcPascal}${modPascal}Response`]);
    }
    if (!excluded.includes(`src/${appBase}/domain/${bcKebab}-${modKebab}.mapper.ts`)) {
        ExportDriver.createExportItems(sourceFile, `./${appBase}/domain/${bcKebab}-${modKebab}.mapper`, [`${bcPascal}${modPascal}Mapper`]);
    }
    if (!excluded.includes(`src/${appBase}/infrastructure/mock/${bcKebab}-mock-${modKebab}.data.ts`)) {
        ExportDriver.createExportItems(sourceFile, `./${appBase}/infrastructure/mock/${bcKebab}-mock-${modKebab}.data`, [`${bcCamel}Mock${modPascal}Data`]);
    }
    sourceFile.saveSync();
}
// eslint-disable-next-line max-params
export function declareBackApiItemsExports(project, srcDirectory, boundedContextName, moduleName, excluded = []) {
    if (excluded.includes('src/@api/**'))
        return;
    const bcKebab = toKebabCase(boundedContextName);
    const modKebab = toKebabCase(moduleName);
    const bcPascal = toPascalCase(boundedContextName);
    const modPascal = toPascalCase(moduleName);
    const sourceFile = project.addSourceFileAtPath(join(process.cwd(), srcDirectory, 'index.ts'));
    if (!excluded.includes(`src/${API_CONTAINER}/${bcKebab}/${bcKebab}.module.ts`)) {
        ExportDriver.createExportItems(sourceFile, `./${API_CONTAINER}/${bcKebab}/${bcKebab}.module`, [`${bcPascal}Module`]);
    }
    if (!excluded.includes(`src/${API_CONTAINER}/${bcKebab}/${modKebab}/dto/${bcKebab}-${modKebab}.dto.ts`)) {
        ExportDriver.createExportItems(sourceFile, `./${API_CONTAINER}/${bcKebab}/${modKebab}/dto/${bcKebab}-${modKebab}.dto`, [`${bcPascal}${modPascal}Dto`]);
    }
    sourceFile.saveSync();
}
export { createProject };
