import { Module, forwardRef } from "@nestjs/common";
import { TypeOrmModule } from "@nestjs/typeorm";
import { Session } from "@tria-plc/iamapi-common/entities/iam/user/session.entity";
import { User } from "@tria-plc/iamapi-common/entities/iam/user/user.entity";

import { BackofficeModule } from "../backoffice/backoffice.module";
import { CompaniesModule } from "../companies/companies.module";
import { NotificationsModule } from "../notifications/notifications.module";
import { Notification } from "./entities/notification.entity";
import { NotificationInboxController } from "./notification-inbox.controller";
import { NotificationInboxRepository } from "./notification-inbox.repository";
import { NotificationInboxService } from "./notification-inbox.service";
import { NotificationRecipientsService } from "./notification-recipients.service";
import { NotificationsGateway } from "./notifications.gateway";
import { WsAuthService } from "./ws-auth.service";

@Module({
  imports: [
    TypeOrmModule.forFeature([Notification, User, Session]),
    // ExternalProfileRepository + CompanyProfileRepository (portal targeting).
    // CompaniesModule imports this module back for CompanyNotifierService.
    forwardRef(() => CompaniesModule),
    // BackofficeService.getOrganizationEmployees (staff targeting)
    BackofficeModule,
    // EmailClientService + SmsClientService (HIGH-priority fan-out)
    NotificationsModule,
  ],
  controllers: [NotificationInboxController],
  providers: [
    NotificationInboxRepository,
    NotificationRecipientsService,
    NotificationsGateway,
    WsAuthService,
    NotificationInboxService,
  ],
  // WsAuthService is reused by the support-chat gateway for handshake auth.
  exports: [NotificationInboxService, WsAuthService],
})
export class NotificationInboxModule {}
