import type { defineModule as defineOrganizationModule } from "../organization";
import { postAccountingEvent } from "./command/postAccountingEvent.generated";
import { createAccountingEventType } from "./db/accountingEvent";

type OrganizationModule = ReturnType<typeof defineOrganizationModule>;
type OrganizationDB = OrganizationModule["db"];
export type OrganizationQueries = OrganizationModule["queries"];

export interface DefineModuleParams {
  organization: {
    db: {
      company: OrganizationDB["company"];
    };
    queries: Pick<OrganizationQueries, "getCompany">;
  };
}

/* @__NO_SIDE_EFFECTS__ */
export const defineModule = (params: DefineModuleParams) => {
  const accountingEventDb = createAccountingEventType({
    companyType: params.organization.db.company,
  });

  return {
    db: {
      accountingEvent: accountingEventDb,
    },
    commands: {
      postAccountingEvent: postAccountingEvent(params.organization.queries),
    },
    queries: {},
  };
};
