import { WinstonLogger } from '@jig-software/logger-winston';
import {
  ConfigDI,
  MongoDI,
  KoaDI,
  container,
  LoggerDI,
} from '@jig-software/sdk';
import { Main } from './Main';
import {
  AppConfig,
  KoaAppOptionsFactory,
  MongoDIOptionsFactory,
  WinstonLoggerParamsFactory,
} from './config';
import { HealthCheckController, ReadingReportController } from './controllers';
import { ActiveAppSettings } from './providers';
import { AppSettingsRepository } from './repositories';
async function bootstrap() {
  container.use(
    ConfigDI.config(AppConfig, { configPath: './volumes/config.json' }),
    LoggerDI.logger(WinstonLogger, {
      paramsFactory: WinstonLoggerParamsFactory,
    }),
    MongoDI.root({ optionsFactory: MongoDIOptionsFactory }),
    KoaDI.root({ optionsFactory: KoaAppOptionsFactory }),
    MongoDI.repository('appSettings', AppSettingsRepository),
    ActiveAppSettings,
  );
  await container.create(KoaDI.controller(HealthCheckController));
  await container.create(KoaDI.controller(ReadingReportController));
  const main = await container.create(Main);
  await main.start();
  process.on('unhandledRejection', console.error);
}

bootstrap().catch(console.error);
