import {
  EnvEncryptionKey
} from "./chunk-IP4OO26U.js";
import {
  AuthController
} from "./chunk-SZVPIHWE.js";
import {
  DrizzleOAuthStateStore
} from "./chunk-N5OTOWTP.js";
import {
  MemoryOAuthStateStore
} from "./chunk-QLTJSCE6.js";
import {
  AUTH_OPTIONS,
  ENCRYPTION_KEY,
  OAUTH_STATE_STORE
} from "./chunk-6XY6ZMMD.js";
import {
  DRIZZLE
} from "./chunk-U64T4YZE.js";
import {
  __decorateClass
} from "./chunk-2E224ZSN.js";

// runtime/subsystems/auth/auth.module.ts
import { Module } from "@nestjs/common";
function resolveEncryptionKeyProvider(choice) {
  if (choice === "env") {
    return { provide: ENCRYPTION_KEY, useClass: EnvEncryptionKey };
  }
  return { provide: ENCRYPTION_KEY, ...choice };
}
function resolveOAuthStateStoreProvider(choice) {
  if (choice === "memory") {
    return { provide: OAUTH_STATE_STORE, useClass: MemoryOAuthStateStore };
  }
  if (choice === "drizzle") {
    return {
      provide: OAUTH_STATE_STORE,
      useFactory: (db) => {
        if (!db) {
          throw new Error(
            "AuthModule.forRoot: oauthStateStore: 'drizzle' selected but DRIZZLE provider is not available. Ensure DatabaseModule (or another provider exposing DRIZZLE) is imported before AuthModule.forRoot."
          );
        }
        return new DrizzleOAuthStateStore(db);
      },
      inject: [{ token: DRIZZLE, optional: true }]
    };
  }
  return { provide: OAUTH_STATE_STORE, ...choice };
}
var AuthModule = class {
  static forRoot(options = {}) {
    const resolved = {
      encryptionKey: options.encryptionKey ?? "env",
      oauthStateStore: options.oauthStateStore ?? "memory",
      enableController: options.enableController ?? false,
      redirectUriBase: options.redirectUriBase
    };
    if (resolved.enableController && !resolved.redirectUriBase) {
      throw new Error(
        "AuthModule.forRoot: redirectUriBase is required when enableController: true"
      );
    }
    const encryptionKeyProvider = resolveEncryptionKeyProvider(
      resolved.encryptionKey
    );
    const oauthStateStoreProvider = resolveOAuthStateStoreProvider(
      resolved.oauthStateStore
    );
    const optionsProvider = {
      provide: AUTH_OPTIONS,
      useValue: resolved
    };
    return {
      module: AuthModule,
      global: true,
      providers: [encryptionKeyProvider, oauthStateStoreProvider, optionsProvider],
      controllers: resolved.enableController ? [AuthController] : [],
      exports: [ENCRYPTION_KEY, OAUTH_STATE_STORE, AUTH_OPTIONS]
    };
  }
};
AuthModule = __decorateClass([
  Module({})
], AuthModule);

export {
  AuthModule
};
//# sourceMappingURL=chunk-T6SCOJF4.js.map