import {
  DrizzleJobRunService
} from "./chunk-5LXOJGO2.js";
import {
  MemoryJobRunService
} from "./chunk-QSJ3J4HE.js";
import {
  DrizzleJobStepService
} from "./chunk-DV4RV2DC.js";
import {
  BULLMQ_CONNECTION,
  BULLMQ_RESOLVED_CONFIG,
  resolveBullMqConfig
} from "./chunk-I6MVCB5A.js";
import {
  DrizzleJobOrchestrator
} from "./chunk-IT6FRTEW.js";
import {
  MemoryJobOrchestrator
} from "./chunk-T4YJRD22.js";
import {
  MemoryJobStepService
} from "./chunk-PNZSGAB2.js";
import {
  MemoryJobStore
} from "./chunk-SNQ3TOWP.js";
import {
  JOBS_LISTEN_NOTIFY,
  JOBS_MULTI_TENANT,
  JOB_ORCHESTRATOR,
  JOB_RUN_SERVICE,
  JOB_STEP_SERVICE
} from "./chunk-ZPL74UQN.js";
import {
  DRIZZLE
} from "./chunk-U64T4YZE.js";
import {
  __decorateClass
} from "./chunk-2E224ZSN.js";

// runtime/subsystems/jobs/jobs-domain.module.ts
import { Module } from "@nestjs/common";
var JobsDomainModule = class {
  static forRoot(opts) {
    const multiTenant = opts.multiTenant ?? false;
    const listenNotify = opts.backend === "drizzle" && Boolean(opts.extensions?.drizzle?.listenNotify);
    const providers = [
      // JOB-8 — boolean provider consumed by the four service-layer backends.
      // Always provided (even when `multiTenant === false`) so `@Inject`
      // always resolves; backends short-circuit the enforcement path when
      // the value is `false`. See `jobs-domain.tokens.ts` for the claim-loop
      // cross-tenant-by-design decision.
      { provide: JOBS_MULTI_TENANT, useValue: multiTenant },
      // LISTEN-NOTIFY-1 — always provided so the orchestrator's `@Inject`
      // resolves; the orchestrator skips the `pg_notify` emit when `false`.
      { provide: JOBS_LISTEN_NOTIFY, useValue: listenNotify }
    ];
    if (opts.backend === "memory") {
      const store = new MemoryJobStore();
      providers.push({ provide: MemoryJobStore, useValue: store });
      providers.push(MemoryJobStepService);
      providers.push({ provide: JOB_STEP_SERVICE, useExisting: MemoryJobStepService });
      providers.push(MemoryJobOrchestrator);
      providers.push({ provide: JOB_ORCHESTRATOR, useExisting: MemoryJobOrchestrator });
      providers.push(MemoryJobRunService);
      providers.push({ provide: JOB_RUN_SERVICE, useExisting: MemoryJobRunService });
    } else if (opts.backend === "bullmq") {
      const resolved = resolveBullMqConfig(opts.extensions?.bullmq);
      providers.push({ provide: BULLMQ_CONNECTION, useValue: resolved.connection });
      providers.push({ provide: BULLMQ_RESOLVED_CONFIG, useValue: resolved });
      providers.push({
        provide: JOB_ORCHESTRATOR,
        useFactory: async (...args) => {
          const specifier = "./job-orchestrator.bullmq-backend";
          const mod = await import(specifier);
          return new mod.BullMQJobOrchestrator(...args);
        },
        // The bullmq orchestrator constructor mirrors DrizzleJobOrchestrator's
        // injection list: DRIZZLE + JOBS_MULTI_TENANT + the resolved BullMQ
        // tokens. Importing token references would force a static dep on the
        // tokens file in this module's import graph; using the existing
        // symbols already in scope is sufficient.
        inject: [DRIZZLE, JOBS_MULTI_TENANT, BULLMQ_CONNECTION, BULLMQ_RESOLVED_CONFIG]
      });
      providers.push({ provide: JOB_RUN_SERVICE, useClass: DrizzleJobRunService });
      providers.push({ provide: JOB_STEP_SERVICE, useClass: DrizzleJobStepService });
    } else {
      providers.push({ provide: JOB_ORCHESTRATOR, useClass: DrizzleJobOrchestrator });
      providers.push({ provide: JOB_RUN_SERVICE, useClass: DrizzleJobRunService });
      providers.push({ provide: JOB_STEP_SERVICE, useClass: DrizzleJobStepService });
    }
    const exports = [
      JOB_ORCHESTRATOR,
      JOB_RUN_SERVICE,
      JOB_STEP_SERVICE,
      JOBS_MULTI_TENANT,
      JOBS_LISTEN_NOTIFY
    ];
    if (opts.backend === "bullmq") {
      exports.push(BULLMQ_CONNECTION, BULLMQ_RESOLVED_CONFIG);
    }
    return {
      module: JobsDomainModule,
      global: true,
      providers,
      exports
    };
  }
};
JobsDomainModule = __decorateClass([
  Module({})
], JobsDomainModule);

export {
  JobsDomainModule
};
//# sourceMappingURL=chunk-DGYTSCKN.js.map