import * as Joi from 'joi';
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import configuration from './configuration';
import { MySQLConfigService } from './config.service';

@Module({
  imports: [
    ConfigModule.forRoot({
      load: [configuration],
      validationSchema: Joi.object({
        MYSQL_HOST: Joi.string().required(),
        MYSQL_USERNAME: Joi.string().required(),
        MYSQL_PASSWORD: Joi.string().required(),
        MYSQL_PORT: Joi.number().default(3306),
        MYSQL_DATABASE: Joi.string().required(),
      }),
    }),
  ],
  providers: [ConfigService, MySQLConfigService],
  exports: [ConfigService, MySQLConfigService],
})
export class MySQLConfigModule {}
