import { Module } from '@nestjs/common'
import { MongooseModule } from '@nestjs/mongoose'
import { AuditModule } from '../audit/audit.module.js'
import { AuthModule } from '../auth/auth.module.js'
import { IntegrationsModule } from '../integrations/integrations.module.js'
import { PricesModule } from '../prices/prices.module.js'
import { Subscription, SubscriptionSchema } from '../schemas/subscription.schema.js'
import { TenantBranding, TenantBrandingSchema } from '../schemas/tenant-branding.schema.js'
import { TenantSsoApp, TenantSsoAppSchema } from '../schemas/tenant-sso-app.schema.js'
import { Tenant, TenantSchema } from '../schemas/tenant.schema.js'
import { User, UserSchema } from '../schemas/user.schema.js'
import { ProvisioningService } from './provisioning.service.js'
import { StorageService } from './storage.service.js'
import { TenantBrandingService } from './tenant-branding.service.js'
import { TenantSsoService } from './tenant-sso.service.js'
import { TenantsController } from './tenants.controller.js'
import { TenantsService } from './tenants.service.js'

@Module({
  imports: [
    MongooseModule.forFeature([
      { name: Tenant.name, schema: TenantSchema },
      { name: User.name, schema: UserSchema },
      // Subscription model accessed directly by TenantsService so a freshly
      // provisioned tenant gets its Subscription doc in the same call. Price
      // lookup goes through PricesService for the soft-active filter.
      { name: Subscription.name, schema: SubscriptionSchema },
      { name: TenantBranding.name, schema: TenantBrandingSchema },
      { name: TenantSsoApp.name, schema: TenantSsoAppSchema },
    ]),
    AuthModule,
    AuditModule,
    IntegrationsModule,
    PricesModule,
  ],
  controllers: [TenantsController],
  providers: [TenantsService, ProvisioningService, TenantBrandingService, StorageService, TenantSsoService],
  exports: [TenantsService],
})
export class TenantsModule {}
