import { type SetupParams, buildTransactionManager } from "@erp/core/api"; import type { IProformaPublicServices } from "@erp/customer-invoices/api"; import type { ICustomerPublicServices } from "@erp/customers/api"; import { buildCreateProformaFromFactugesUseCase, buildFactugesInputMappers, } from "../../application/di"; import { buildFactuGESCatalogResolvers } from "../../application/di/factuges-catalog-resolvers.di"; import { buildFactuGESFinder } from "../../application/di/factuges-finder.di"; import { buildFactuGESLinker } from "../../application/di/factuges-linker.di"; import { createFactuGESPaymentReferenceProvider } from "../../application/services/json-data"; import type { CreateProformaFromFactugesUseCase } from "../../application/use-cases"; import { resolveFactuGESCatalogsDeps } from "./factuges-catalog-deps.di"; import { buildFactuGESPersistenceMappers } from "./factuges-persistence-mappers.di"; import { buildFactugesRepository } from "./factuges-repositories.di"; export type FactugesInternalDeps = { useCases: { createProforma: (publicServices: { customerServices: ICustomerPublicServices; proformaServices: IProformaPublicServices; }) => CreateProformaFromFactugesUseCase; }; }; export function buildFactugesDependencies(params: SetupParams): FactugesInternalDeps { const { database, transactionContext } = params; const catalogs = resolveFactuGESCatalogsDeps(params); // Infrastructure const transactionManager = buildTransactionManager(database, transactionContext); const inputMappers = buildFactugesInputMappers(); const persistenceMappers = buildFactuGESPersistenceMappers(); const repository = buildFactugesRepository({ database, mappers: persistenceMappers }); const paymentReferenceProvider = createFactuGESPaymentReferenceProvider(); const catalogResolvers = buildFactuGESCatalogResolvers({ taxDefinitionFinder: catalogs.taxDefinition.finder, taxRegimeFinder: catalogs.taxRegime.finder, paymentMethodFinder: catalogs.paymentMethod.finder, paymentTermFinder: catalogs.paymentTerm.finder, paymentReferenceProvider: paymentReferenceProvider, }); // Application helpers const finder = buildFactuGESFinder({ repository }); const linker = buildFactuGESLinker({ repository }); // Internal use cases (factories) return { useCases: { createProforma: (publicServices: { customerServices: ICustomerPublicServices; proformaServices: IProformaPublicServices; }) => buildCreateProformaFromFactugesUseCase({ linker, finder, dtoMapper: inputMappers.createInputMapper, catalogResolvers: catalogResolvers, publicServices, transactionManager, }), }, }; }