import { Module } from '@nestjs/common'
import { MongooseModule } from '@nestjs/mongoose'
import { JwtModule } from '@nestjs/jwt'
import { PassportModule } from '@nestjs/passport'
import { ThrottlerModule } from '@nestjs/throttler'
import { ScheduleModule as NestScheduleModule } from '@nestjs/schedule'
import { APP_GUARD } from '@nestjs/core'

import { JwtStrategy } from './common/strategies/jwt.strategy'
import { JwtAuthGuard } from './common/guards/jwt-auth.guard'
import { AiModule } from './modules/ai/ai.module'
import { FeedbackModule } from './modules/feedback/feedback.module'
import { UserModule } from './modules/user/user.module'
import { InterviewModule } from './modules/interview/interview.module'
import { ResumeModule } from './modules/resume/resume.module'
import { EmailModule } from './modules/email/email.module'
import { PaymentModule } from './modules/payment/payment.module'
import { MemberModule } from './modules/member/member.module'
import { AdminModule } from './modules/admin/admin.module'
import { UploadModule } from './modules/upload/upload.module'
import { PositionsModule } from './modules/positions/positions.module'
import { AnalyzeModule } from './modules/analyze/analyze.module'
import { ProgressModule } from './modules/progress/progress.module'
import { ContributionModule } from './modules/contribution/contribution.module'
import { DailyQuestionModule } from './modules/daily-question/daily-question.module'
import { ScheduleModule } from './modules/schedule/schedule.module'
import { TtsModule } from './modules/tts/tts.module'
import { PricingModule } from './modules/schemas/pricing.module'
import { GravityTransactionModule } from './modules/schemas/gravity-transaction.module'
import { ShareModule } from './modules/share/share.module'
import { InterviewReviewModule } from './modules/interview-review/interview-review.module'
import { CareerAdviceModule } from './modules/career-advice/career-advice.module'
import { VirtualPaymentModule } from './modules/virtual-payment/virtual-payment.module'

const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/zhiyin'

@Module({
  imports: [
    MongooseModule.forRoot(MONGODB_URI),
    PassportModule.register({ defaultStrategy: 'jwt' }),
    JwtModule.register({
      secret: process.env.JWT_SECRET,
      signOptions: { expiresIn: '7d' },
    }),
    ThrottlerModule.forRoot([{
      ttl: 60000,
      limit: 100,
    }]),
    NestScheduleModule.forRoot(),
    UserModule,
    FeedbackModule,
    AiModule,
    InterviewModule,
    AnalyzeModule,
    ResumeModule,
    PositionsModule,
    UploadModule,
    AdminModule,
    MemberModule,
    EmailModule,
    PaymentModule,
    ProgressModule,
    ContributionModule,
    DailyQuestionModule,
    ScheduleModule,
    TtsModule,
    PricingModule,
    ShareModule,
    InterviewReviewModule,
    CareerAdviceModule,
    VirtualPaymentModule,
    GravityTransactionModule,
  ],
  providers: [
    JwtStrategy,
    { provide: APP_GUARD, useClass: JwtAuthGuard },
  ],
})
export class AppModule {}