import { Module, forwardRef } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AuthToken } from './entities/AuthToken';
import { AuthService } from './services/AuthService';
import { AuthController } from './controllers/AuthController';
import { JwtAuthGuard } from './guards/JwtAuthGuard';
import { RolesGuard } from './guards/RolesGuard';

// 导入Admin和Member模块
import { AdminModule } from '../admin/admin.module';
import { MemberModule } from '../member/member.module';

@Module({
  imports: [
    PassportModule,
    TypeOrmModule.forFeature([AuthToken]),
    JwtModule.registerAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        secret: configService.get('JWT_SECRET', 'change_me'),
        signOptions: {
          expiresIn: configService.get('JWT_EXPIRES_IN', '7d'),
        },
      }),
      inject: [ConfigService],
    }),
    // 导入Admin和Member模块以使用其服务
    forwardRef(() => AdminModule),
    forwardRef(() => MemberModule),
  ],
  providers: [
    AuthService,
    JwtAuthGuard,
    RolesGuard,
  ],
  controllers: [AuthController],
  exports: [
    AuthService,
    JwtAuthGuard,
    RolesGuard,
  ],
})
export class AuthModule {} 