import { join } from 'path';

import { CacheInterceptor, Module } from '@nestjs/common';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { AngularUniversalModule } from '@nestjs/ng-universal';
import { ConfigModule } from '@nestjs/config';
import { GraphQLModule } from '@nestjs/graphql';

import { AppServerModule } from '../src/main.server';
import { AuthenticationModule } from './authentication/authentication.module';
import { DatabaseService } from './database/database.service';
import { AuthorizationModule } from './authorization/authorization.module';
import { EmailModule } from './email/email.module';
import { ClubResolver } from './club/club.resolver';
import { PlayerResolver } from './player/player.resolver';
import { GroupResolver } from './group/group.resolver';
import { GameDataResolver } from './game-data/game-data.resolver';
import { StationsResolver } from './stations/stations.resolver';
import { UserResolver } from './user/user.resolver';

@Module({
  imports: [
    AngularUniversalModule.forRoot({
      bootstrap: AppServerModule,
      viewsPath: join(process.cwd(), 'dist/agineek-website/browser')
    }),
    ConfigModule.forRoot({
      isGlobal: true,
      cache: true
    }),
    GraphQLModule.forRoot({
      autoSchemaFile: join(process.cwd(), 'server/schema.graphql'),
      sortSchema: true,
      context: ({ req }) => ({ req }),
      debug: process.env.NODE_ENV === 'development',
      playground: process.env.NODE_ENV === 'development'
    }),
    AuthenticationModule,
    AuthorizationModule,
    EmailModule
  ],
  providers: [
    DatabaseService,
    ClubResolver,
    PlayerResolver,
    GroupResolver,
    GameDataResolver,
    StationsResolver,
    UserResolver
  ],
  controllers: [],
  exports: [ConfigModule]
})
export class AppModule {}
