import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { PassportModule } from '@nestjs/passport';
import { JwtModule } from '@nestjs/jwt';

// Domain
import { ReferralProfile } from './domain/entities/referral-profile.entity';
import { REFERRAL_PROFILE_REPOSITORY } from './domain/repositories/referral-profile.repository.interface';

// Infrastructure
import { ReferralProfileRepository } from './infrastructure/persistence/referral-profile.repository';
import { JwtStrategy } from './infrastructure/strategies/jwt.strategy';

// Application
import { ReferralService } from './application/services/referral.service';
import { UserRegisteredHandler } from './application/event-handlers/user-registered.handler';

// Interface
import { ReferralController } from './interface/http/controllers/referral.controller';
import { InternalReferralController } from './interface/http/controllers/internal-referral.controller';
import { HealthController } from './interface/http/controllers/health.controller';

@Module({
  imports: [
    TypeOrmModule.forFeature([ReferralProfile]),
    PassportModule.register({ defaultStrategy: 'jwt' }),
    JwtModule.register({
      secret: process.env.JWT_ACCESS_SECRET || 'dev-access-secret',
      signOptions: { expiresIn: '15m' },
    }),
  ],
  controllers: [HealthController, ReferralController, InternalReferralController],
  providers: [
    { provide: REFERRAL_PROFILE_REPOSITORY, useClass: ReferralProfileRepository },
    JwtStrategy,
    ReferralService,
    UserRegisteredHandler,
  ],
  exports: [ReferralService],
})
export class ReferralModule {}
