import { DynamicModule } from '@nestjs/common';
import { BullMqExtensionsConfig } from './bullmq.config.js';
import './pool-config.loader.js';

/**
 * JobsDomainModule — `DynamicModule.forRoot({ backend })` factory wiring
 * the three jobs-domain protocol tokens to a backend implementation
 * (ADR-022, JOB-5).
 *
 * Mirrors `EventsModule.forRoot()` exactly:
 *   - `global: true` so consumer entity modules don't have to import this
 *     individually — `JOB_ORCHESTRATOR` / `JOB_RUN_SERVICE` /
 *     `JOB_STEP_SERVICE` are available project-wide.
 *   - One backend at a time (Drizzle for production, Memory for tests).
 *
 * Backend swappability follows the core/extension protocol from CLAUDE.md:
 * the three tokens are the **core contract**; backend-specific tunables
 * live under `extensions.<backend>` so opting into a feature is explicit
 * and the type system reserves the slot.
 */

/**
 * Drizzle backend extensions surface (LISTEN-NOTIFY-1 wires both fields).
 *
 * - `listenNotify` → provided as `JOBS_LISTEN_NOTIFY` so the orchestrator emits
 *   in-tx `pg_notify` on enqueue, and threaded into each spawned `JobWorker`
 *   (which holds the listener connection). Off by default.
 * - `pollIntervalMs` → threaded into the spawned `JobWorker`'s
 *   `JobWorkerOptions.pollIntervalMs` (the worker already honored this; it just
 *   never received a config value). Default 1000.
 *
 * Both run ALONGSIDE interval polling — `listenNotify` only adds an early wake;
 * polling remains the durability heartbeat.
 */
interface DrizzleBackendExtensions {
    /** Use Postgres LISTEN/NOTIFY to wake the polling loop. Default false. */
    listenNotify?: boolean;
    /** Polling interval (ms). Default 1000. */
    pollIntervalMs?: number;
}
interface JobsDomainModuleOptions {
    backend: 'drizzle' | 'memory' | 'bullmq';
    /**
     * Backend-specific extensions. Only the matching backend's extensions
     * are read at boot; non-matching keys are ignored. This is the
     * core/extension protocol surface — see CLAUDE.md.
     */
    extensions?: {
        drizzle?: DrizzleBackendExtensions;
        /**
         * BullMQ backend extensions (BULLMQ-1). Snake_case mirrors the YAML
         * under `jobs.extensions.bullmq`. `redis_url` falls back to
         * `process.env.REDIS_URL` then `redis://localhost:6379`.
         */
        bullmq?: BullMqExtensionsConfig;
    };
    /** Multi-tenancy opt-in. Wired by JOB-8; module signature stays stable. */
    multiTenant?: boolean;
}
declare class JobsDomainModule {
    static forRoot(opts: JobsDomainModuleOptions): DynamicModule;
}

export { type DrizzleBackendExtensions, JobsDomainModule, type JobsDomainModuleOptions };
