import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AdminModule } from './admin/admin.module';
import { Admin } from './admin/entities/admin.entity';
import { DbConstants } from './constants/db.constants';
import { AuthAdminModule } from './auth/admin/authAdmin.module';
import { UserModule } from './user/user.module';
import { User } from './user/entities/user.entity';
import { AuthUserModule } from './auth/user/authUser.module';
import { StateModule } from './state/state.module';
import { DatabaseSeederModule } from './database-seeder/database-seeder.module';
import { State } from './state/entities/state.entity';
import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';
import { Town } from './town/entities/town.entity';
import { TownModule } from './town/town.module';
import { TownTraduction } from './town/entities/town-traduction.entity';
import { PlaceModule } from './place/place.module';
import { Place } from './place/entities/place.entity';
import { PointOfInterestModule } from './pointOfInterest/PointOfInterest.module';
import { PointOfInterest } from './pointOfInterest/entities/PointOfInterest.entity';
import { AvailableDate } from './place/entities/available-date.entity';
import { PointOfInterestTraduction } from './pointOfInterest/entities/PointOfInterestTraduction.entity';
import { PlaceTraduction } from './place/entities/place-traduction.entity';
import { CategoryModule } from './category/category.module';
import { Category } from './category/entities/category.entity';
import { RouteModule } from './route/route.module';
import { Route } from './route/entities/route.entity';
import { TravelPlaceModule } from './travel-place/travel-place.module';
import { TravelPlace } from './travel-place/entities/travel-place.entity';
import { VisitedModule } from './visited/visited.module';
import { Visited } from './visited/entities/visited.entity';
import { EmailService } from './email/email.service';
import { UserResetCode } from './auth/user/entities/user-reset-code.entity';
import { MailerModule } from '@nestjs-modules/mailer';
import { MailConstants } from './constants/mail.constants';
import { AdminResetCode } from './auth/admin/entitites/admin-reset-code.entity';
import { UserConfirmCode } from './auth/user/entities/user-confirm-code.entity';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: DbConstants.DB_HOST,
      port: DbConstants.DB_PORT,
      username: DbConstants.DB_USER,
      password: DbConstants.DB_PASSWORD,
      database: DbConstants.DB_NAME,
      entities: [
        Admin,
        User,
        State,
        Town,
        TownTraduction,
        Place,
        PointOfInterest,
        AvailableDate,
        PointOfInterestTraduction,
        PlaceTraduction,
        Category,
        Route,
        TravelPlace,
        Visited,
        UserResetCode,
        AdminResetCode,
        UserConfirmCode,
      ],
      synchronize: DbConstants.DB_SYNC,
      logging: false,
    }),
    MailerModule.forRoot({
      transport: {
        host: MailConstants.MAIL_HOST,
        port: 587,
        secure: false,
        auth: {
          user: MailConstants.MAIL_USER,
          pass: MailConstants.MAIL_PASSWORD,
        },
      },
      defaults: {
        from: '"No Reply" <noreplt@example.com>',
      },
    }),
    AuthAdminModule,
    AdminModule,
    UserModule,
    AuthUserModule,
    StateModule,
    DatabaseSeederModule,
    TownModule,
    PlaceModule,
    ServeStaticModule.forRoot({
      rootPath: join(__dirname, '..', 'static'),
    }),
    PointOfInterestModule,
    CategoryModule,
    RouteModule,
    TravelPlaceModule,
    VisitedModule,
  ],
  controllers: [AppController],
  providers: [AppService, DatabaseSeederModule, EmailService],
  exports: [TypeOrmModule],
})
export class AppModule {}
