import { InMemoryMapperRegistry, InMemoryPresenterRegistry, SequelizeTransactionManager } from "@erp/core/api";
import type { ModuleParams } from "@erp/core/api";
import { {{pascalCase name}}Repository } from "./{{kebabCase name}}.repository";
import { Create{{pascalCase name}}Controller, Delete{{pascalCase name}}Controller, Get{{pascalCase name}}Controller, List{{pascalCase name}}Controller, Update{{pascalCase name}}Controller } from "../express/controllers";
// Los use-cases/servicios se resuelven desde application/domain (puede no compilar hasta que existan)
import {
  Create{{pascalCase name}}UseCase,
  Delete{{pascalCase name}}UseCase,
  Get{{pascalCase name}}UseCase,
  List{{pascalCase name}}UseCase,
  Update{{pascalCase name}}UseCase,
} from "../../application";
import { {{pascalCase name}}Service } from "../../domain";

/**
 * Wiring/DI de infraestructura del módulo
 */
export const build{{pascalCase name}}Dependencies = (params: ModuleParams) => {
  const mapperRegistry = new InMemoryMapperRegistry();
  const presenterRegistry = new InMemoryPresenterRegistry();
  const transactionManager = new SequelizeTransactionManager(params.database);

  const repository = new {{pascalCase name}}Repository(params.database);
  const service = new {{pascalCase name}}Service(repository);

  // TODO: enlazar presenters reales cuando existan
  // presenterRegistry.register("{{camelCase name}}.created", ...);

  return {
    mapperRegistry,
    presenterRegistry,
    transactionManager,
    repository,
    service,
    build: {
      list: () => new List{{pascalCase name}}Controller(new List{{pascalCase name}}UseCase(service)),
      get: () => new Get{{pascalCase name}}Controller(new Get{{pascalCase name}}UseCase(service)),
      create: () => new Create{{pascalCase name}}Controller(new Create{{pascalCase name}}UseCase(service)),
      update: () => new Update{{pascalCase name}}Controller(new Update{{pascalCase name}}UseCase(service)),
      delete: () => new Delete{{pascalCase name}}Controller(new Delete{{pascalCase name}}UseCase(service)),
    },
  };
};
