import { Module } from '@nestjs/common'
import { MongooseModule } from '@nestjs/mongoose'
import { AuditModule } from '../audit/audit.module.js'
import { IntegrationsModule } from '../integrations/integrations.module.js'
import {
  IngestCursor,
  IngestCursorSchema,
} from '../schemas/ingest-cursor.schema.js'
import { Tenant, TenantSchema } from '../schemas/tenant.schema.js'
import { User, UserSchema } from '../schemas/user.schema.js'
import { AuthentikIngest } from './authentik.ingest.js'
import { OcisIngest } from './ocis.ingest.js'
import { StalwartWebhookController } from './stalwart-webhook.controller.js'

// Workers + endpoints that bring audit events from external systems into
// AuditService. Authentik = polling worker (pull). Stalwart = webhook
// endpoint (push). OCIS = file-tail worker (pull from a JSON-Lines log on a
// shared volume). Each integration owns its own cursor / dedup story.
@Module({
  imports: [
    AuditModule,
    IntegrationsModule,
    MongooseModule.forFeature([
      { name: IngestCursor.name, schema: IngestCursorSchema },
      { name: Tenant.name, schema: TenantSchema },
      { name: User.name, schema: UserSchema },
    ]),
  ],
  controllers: [StalwartWebhookController],
  providers: [AuthentikIngest, OcisIngest],
})
export class IngestModule {}
