import { type DynamicModule, Global, Module } from "@nestjs/common";

import { VAULT_MODULE_OPTIONS } from "./vault.constants.js";
import { VaultService } from "./vault.service.js";
import type { VaultConfig } from "./vault.types.js";

@Global()
@Module({})
export class VaultModule {
  static forRoot(config: VaultConfig): DynamicModule {
    return {
      module: VaultModule,
      providers: [
        {
          provide: VAULT_MODULE_OPTIONS,
          useValue: config,
        },
        VaultService,
      ],
      exports: [VaultService],
    };
  }
}
