import { Module } from '@nestjs/common';
import { APP_GUARD } from '@nestjs/core';
import { ConfigModule } from '@nestjs/config';
import { ThrottlerModule } from '@nestjs/throttler';
import configuration from './config/configuration';
import { TierThrottlerGuard } from './common/guards/tier-throttler.guard';
import { BlocksController } from './modules/blocks/blocks.controller';
import { BlocksService } from './modules/blocks/blocks.service';
import { TransactionsController } from './modules/transactions/transactions.controller';
import { TransactionsService } from './modules/transactions/transactions.service';
import { AddressController } from './modules/address/address.controller';
import { AddressService } from './modules/address/address.service';
import { CouponController } from './modules/coupon/coupon.controller';
import { CouponService } from './modules/coupon/coupon.service';
import { StatsController } from './modules/stats/stats.controller';
import { StatsService } from './modules/stats/stats.service';
import { RpcController } from './modules/rpc/rpc.controller';
import { RpcService } from './modules/rpc/rpc.service';
import { ExportController } from './modules/export/export.controller';
import { ExportService } from './modules/export/export.service';
import { RegulatoryController } from './modules/regulatory/regulatory.controller';
import { RegulatoryService } from './modules/regulatory/regulatory.service';
import { EventsGateway } from './modules/events/events.gateway';
import { EventsService } from './modules/events/events.service';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true, load: [configuration] }),
    ThrottlerModule.forRoot([{ ttl: 60000, limit: 600 }]),
  ],
  controllers: [
    BlocksController,
    TransactionsController,
    AddressController,
    CouponController,
    StatsController,
    RpcController,
    ExportController,
    RegulatoryController,
  ],
  providers: [
    // 全局分层限流守卫（按 API tier 区分：public 60/min, institutional 600/min, regulatory unlimited）
    { provide: APP_GUARD, useClass: TierThrottlerGuard },
    BlocksService,
    TransactionsService,
    AddressService,
    CouponService,
    StatsService,
    RpcService,
    ExportService,
    RegulatoryService,
    EventsGateway,
    EventsService,
  ],
})
export class AppModule {}
