import { Module, Global, Provider } from '@nestjs/common';
import * as models from './models';

const modelProviders: Provider[] = Object.values(models)
  .filter(
    (model: any) =>
      typeof model === 'function' &&
      model.prototype &&
      (model.prototype instanceof models.BaseModel || model === models.BaseModel),
  )
  .map((model: any) => ({
    provide: model,
    useValue: model,
  }));

@Global()
@Module({
  providers: modelProviders,
  exports: modelProviders,
})
export class ModelsModule {}
