import { IModuleServer, ModuleParams } from "@erp/core/api";
import { UniqueID } from "@repo/rdx-ddd";
import { Transaction } from "sequelize";
import { customerInvoicesRouter, models } from "./infrastructure";
import { buildCustomerInvoiceDependencies } from "./infrastructure/dependencies";

export const customerInvoicesAPIModule: IModuleServer = {
  name: "customer-invoices",
  version: "1.0.0",
  dependencies: ["customers"],

  async init(params: ModuleParams) {
    // const contacts = getService<ContactsService>("contacts");
    const { logger } = params;
    customerInvoicesRouter(params);
    logger.info("🚀 CustomerInvoices module initialized", { label: this.name });
  },

  async registerDependencies(params) {
    const { logger, listServices } = params; /* = ModuleParams & {
      getService: (name: string) => any;
    };*/

    logger.info("🚀 CustomerInvoices module dependencies registered", {
      label: this.name,
    });

    logger.info(listServices());
    //getService()

    const deps = buildCustomerInvoiceDependencies(params);

    return {
      models,
      services: {
        getInvoiceByIdInCompany: (
          companyId: UniqueID,
          invoiceId: UniqueID,
          transaction?: Transaction
        ) => {
          const { service } = deps;

          return service.getInvoiceByIdInCompany(companyId, invoiceId, transaction);
        },
      },
    };
  },
};

export default customerInvoicesAPIModule;
