import { Module, forwardRef } from '@nestjs/common'
import { MongooseModule } from '@nestjs/mongoose'
import { AuditModule } from '../audit/audit.module.js'
import { AuthModule } from '../auth/auth.module.js'
import { Partner, PartnerSchema } from '../schemas/partner.schema.js'
import { Tenant, TenantSchema } from '../schemas/tenant.schema.js'
import { UsersModule } from '../users/users.module.js'
import { PartnersController } from './partners.controller.js'
import { PartnersService } from './partners.service.js'

@Module({
  imports: [
    MongooseModule.forFeature([
      { name: Partner.name, schema: PartnerSchema },
      { name: Tenant.name, schema: TenantSchema },
    ]),
    AuthModule,
    AuditModule,
    // forwardRef defensively — if UsersModule ever grows a dependency back
    // on PartnersModule (e.g. partner-portal scope guards that need
    // PartnersService.findOneBySlug), we avoid the circular-dep refactor.
    forwardRef(() => UsersModule),
  ],
  controllers: [PartnersController],
  providers: [PartnersService],
  exports: [PartnersService],
})
export class PartnersModule {}
