import { DynamicModule } from '@nestjs/common'
import { ViewModule } from '@view/view.module'

import type { UploadConfigValues } from './upload.config'
import { UploadConfig } from './upload.config'
import { UploadController } from './upload.controller'
import { UploadService } from './upload.service'

export class UploadModule {
  static forRoot(config: UploadConfigValues): DynamicModule {
    return {
      module: UploadModule,
      imports: [ViewModule],
      providers: [
        UploadService,
        {
          provide: UploadConfig,
          useValue: new UploadConfig(config),
        },
      ],
      controllers: [UploadController],
      exports: [UploadService],
      global: true,
    }
  }
}
