import { Module } from "@nestjs/common";
import { APP_GUARD } from "@nestjs/core";
import { AuthOrchestrator } from "./application/auth-orchestrator.service.js";
import { AuthHealthService } from "./application/auth-health.service.js";
import { AuthLoginService } from "./application/auth-login.service.js";
import { AuthController } from "./presentation/http/auth.controller.js";
import { UsersModule } from "@bff/modules/users/users.module.js";
import { MappingsModule } from "@bff/modules/id-mappings/mappings.module.js";
import { IntegrationsModule } from "@bff/integrations/integrations.module.js";
import { GlobalAuthGuard } from "./presentation/http/guards/global-auth.guard.js";
import { PermissionsGuard } from "./presentation/http/guards/permissions.guard.js";
import { TokenBlacklistService } from "./infra/token/token-blacklist.service.js";
import { TokenStorageService } from "./infra/token/token-storage.service.js";
import { TokenRevocationService } from "./infra/token/token-revocation.service.js";
import { PasswordResetTokenService } from "./infra/token/password-reset-token.service.js";
import { CacheModule } from "@bff/infra/cache/cache.module.js";
import { AuthTokenService } from "./infra/token/token.service.js";
import { JoseJwtService } from "./infra/token/jose-jwt.service.js";
import { SignupWorkflowService } from "./infra/workflows/signup-workflow.service.js";
import { PasswordWorkflowService } from "./infra/workflows/password-workflow.service.js";
import { WhmcsLinkWorkflowService } from "./infra/workflows/whmcs-link-workflow.service.js";
import { FailedLoginThrottleGuard } from "./presentation/http/guards/failed-login-throttle.guard.js";
import { LoginResultInterceptor } from "./presentation/http/interceptors/login-result.interceptor.js";
import { AuthRateLimitService } from "./infra/rate-limiting/auth-rate-limit.service.js";
import { SignupAccountResolverService } from "./infra/workflows/signup/signup-account-resolver.service.js";
import { SignupValidationService } from "./infra/workflows/signup/signup-validation.service.js";
import { SignupWhmcsService } from "./infra/workflows/signup/signup-whmcs.service.js";
import { SignupUserCreationService } from "./infra/workflows/signup/signup-user-creation.service.js";
// Get Started flow
import { OtpService } from "./infra/otp/otp.service.js";
import { GetStartedSessionService } from "./infra/otp/get-started-session.service.js";
import { GetStartedWorkflowService } from "./infra/workflows/get-started-workflow.service.js";
import { GetStartedController } from "./presentation/http/get-started.controller.js";
import { WorkflowModule } from "@bff/modules/shared/workflow/index.js";

@Module({
  imports: [UsersModule, MappingsModule, IntegrationsModule, CacheModule, WorkflowModule],
  controllers: [AuthController, GetStartedController],
  providers: [
    // Application services
    AuthOrchestrator,
    AuthHealthService,
    AuthLoginService,
    // Token services
    TokenBlacklistService,
    TokenStorageService,
    TokenRevocationService,
    AuthTokenService,
    JoseJwtService,
    PasswordResetTokenService,
    // Signup workflow services
    SignupWorkflowService,
    SignupAccountResolverService,
    SignupValidationService,
    SignupWhmcsService,
    SignupUserCreationService,
    // Other workflow services
    PasswordWorkflowService,
    WhmcsLinkWorkflowService,
    // Get Started flow services
    OtpService,
    GetStartedSessionService,
    GetStartedWorkflowService,
    // Guards and interceptors
    FailedLoginThrottleGuard,
    AuthRateLimitService,
    LoginResultInterceptor,
    PermissionsGuard,
    {
      provide: APP_GUARD,
      useClass: GlobalAuthGuard,
    },
    {
      provide: APP_GUARD,
      useClass: PermissionsGuard,
    },
  ],
  exports: [AuthOrchestrator, TokenBlacklistService, AuthTokenService, PermissionsGuard],
})
export class AuthModule {}
