import { DynamicModule, Provider } from '@nestjs/common'

import { Config, XlPortConfig } from './xlport.config'
import { XlPortService } from './xlport.service'

export class XlPortModule {
  static forRoot(config: Config): DynamicModule {
    const configProvider: Provider = {
      provide: XlPortConfig,
      useFactory: () => new XlPortConfig(config),
    }
    return {
      module: XlPortModule,
      imports: [],
      providers: [configProvider, XlPortService],
      exports: [XlPortService],
      global: true,
    }
  }
}
