import { Module, Global } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { MerchantAuthController } from './auth.controller';
import { MerchantAuthService } from './auth.service';
import { Seller } from '@/entities/seller.entity';
import { Merchant } from '@/entities/merchant.entity';

@Global()
@Module({
  imports: [
    TypeOrmModule.forFeature([Seller, Merchant]),
    JwtModule.registerAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        secret: configService.get<string>('jwt.secret') || 'dev_secret_key',
        signOptions: {
          expiresIn: (configService.get<string>('jwt.expiresIn') ||
            '2h') as any,
        },
      }),
      inject: [ConfigService],
    }),
  ],
  controllers: [MerchantAuthController],
  providers: [MerchantAuthService],
  exports: [MerchantAuthService, JwtModule],
})
export class MerchantAuthModule {}
