import { Module } from '@nestjs/common'
import { MongooseModule } from '@nestjs/mongoose'
import { IntegrationsModule } from '../../integrations/integrations.module.js'
import { Host, HostSchema } from '../../schemas/scheduling-host.schema.js'
import { StalwartCredential, StalwartCredentialSchema } from '../../schemas/stalwart-credential.schema.js'
import { CredentialCipher } from '../crypto/credential-cipher.js'
import { CredentialProvisioner } from './credential-provisioner.service.js'
import { JmapCalendarGateway } from './jmap-calendar.gateway.js'

// Isolated Stalwart calendar integration — the only place that knows JMAP. Kept
// self-contained so it can be extracted to a microservice later (CLAUDE.md).
@Module({
  imports: [
    MongooseModule.forFeature([
      { name: StalwartCredential.name, schema: StalwartCredentialSchema },
      { name: Host.name, schema: HostSchema },
    ]),
    IntegrationsModule, // StalwartClient (admin JMAP) for app-password provisioning
  ],
  providers: [CredentialCipher, CredentialProvisioner, JmapCalendarGateway],
  exports: [CredentialProvisioner, JmapCalendarGateway],
})
export class StalwartCalendarModule {}
