import { Module } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
import { APP_GUARD } from "@nestjs/core";
import { ThrottlerGuard, ThrottlerModule } from "@nestjs/throttler";
import { LoggerModule } from "nestjs-pino";
import { AdminAuthModule } from "./admin-auth/admin-auth.module";
import { AdminEventsModule } from "./admin-events/admin-events.module";
import { ApiKeyModule } from "./api-keys/api-key.module";
import { BillingModule } from "./billing/billing.module";
import { CheckoutSessionModule } from "./checkout-sessions/checkout-session.module";
import { AuthModule } from "./common/auth/auth.module";
import { CryptoModule } from "./common/crypto/crypto.module";
import { CustomerModule } from "./customers/customer.module";
import { HealthModule } from "./health/health.module";
import { MerchantModule } from "./merchants/merchant.module";
import { PaymentIntentModule } from "./payment-intents/payment-intent.module";
import { PrismaModule } from "./prisma/prisma.module";
import { ProviderConfigModule } from "./provider-configs/provider-config.module";
import { ProviderModule } from "./providers/provider.module";
import { RefundModule } from "./refunds/refund.module";
import { WebhookEndpointModule } from "./webhook-endpoints/webhook-endpoint.module";
import { WebhookEventModule } from "./webhook-events/webhook-event.module";
import { WebhookInboundModule } from "./webhook-inbound/webhook-inbound.module";

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    LoggerModule.forRoot({
      pinoHttp: {
        level: process.env.LOG_LEVEL ?? "info",
        transport:
          process.env.NODE_ENV === "production"
            ? undefined
            : { target: "pino-pretty", options: { singleLine: true } },
      },
    }),
    ThrottlerModule.forRoot([
      { name: "short", ttl: 1_000, limit: 50 },
      { name: "long", ttl: 60_000, limit: 1_200 },
    ]),
    PrismaModule,
    CryptoModule,
    AuthModule,
    HealthModule,
    MerchantModule,
    ApiKeyModule,
    CustomerModule,
    ProviderConfigModule,
    PaymentIntentModule,
    CheckoutSessionModule,
    WebhookEndpointModule,
    ProviderModule,
    WebhookEventModule,
    WebhookInboundModule,
    RefundModule,
    AdminAuthModule,
    AdminEventsModule,
    BillingModule,
  ],
  providers: [{ provide: APP_GUARD, useClass: ThrottlerGuard }],
})
export class AppModule {}
