import { Module } from '@nestjs/common';
import { PassportModule } from '@nestjs/passport';
import { JwtModule } from '@nestjs/jwt';
import { ConfigService } from '@nestjs/config';
import {
  WalletController,
  LedgerController,
  DepositController,
  HealthController,
  SystemWithdrawalController,
} from './controllers';
import { InternalWalletController } from './controllers/internal-wallet.controller';
import { FiatWithdrawalController } from './controllers/fiat-withdrawal.controller';
// [2026-02-19] 纯新增：转让钱包内部 Controller
import { InternalTransferWalletController } from './controllers/internal-transfer-wallet.controller';
import { WalletApplicationService, FiatWithdrawalApplicationService, SystemWithdrawalApplicationService } from '@/application/services';
import { DepositConfirmedHandler, PlantingCreatedHandler, UserAccountCreatedHandler } from '@/application/event-handlers';
import { WithdrawalStatusHandler } from '@/application/event-handlers/withdrawal-status.handler';
import { SystemWithdrawalStatusHandler } from '@/application/event-handlers/system-withdrawal-status.handler';
import { ExpiredRewardsScheduler } from '@/application/schedulers';
import { JwtStrategy } from '@/shared/strategies/jwt.strategy';

@Module({
  imports: [
    PassportModule.register({ defaultStrategy: 'jwt' }),
    JwtModule.registerAsync({
      inject: [ConfigService],
      useFactory: (config: ConfigService) => ({
        secret: config.get<string>('JWT_SECRET') || 'default-secret',
        signOptions: { expiresIn: '7d' },
      }),
    }),
  ],
  controllers: [
    WalletController,
    LedgerController,
    DepositController,
    HealthController,
    InternalWalletController,
    FiatWithdrawalController,
    SystemWithdrawalController,
    InternalTransferWalletController, // [2026-02-19] 纯新增：转让钱包内部端点
  ],
  providers: [
    WalletApplicationService,
    FiatWithdrawalApplicationService,
    SystemWithdrawalApplicationService,
    DepositConfirmedHandler,
    PlantingCreatedHandler,
    // [2026-01-08] 新增：用户注册时创建钱包的事件处理器
    UserAccountCreatedHandler,
    WithdrawalStatusHandler,
    SystemWithdrawalStatusHandler,
    ExpiredRewardsScheduler,
    JwtStrategy,
  ],
})
export class ApiModule {}
