import { Module } from '@nestjs/common';
import { CredentialsModule } from './credentials/credentials.module';
import { SyncModule } from './sync/sync.module';
import { StatusModule } from './status/status.module';
import { JobsModule } from './jobs/jobs.module';

// Connector modules
import { PlentyoneModule } from './connectors/plentyone/plentyone.module';
import { ZulipModule } from './connectors/zulip/zulip.module';
import { TodoistModule } from './connectors/todoist/todoist.module';
import { FreeScoutModule } from './connectors/freescout/freescout.module';
import { NextcloudModule } from './connectors/nextcloud/nextcloud.module';
import { EcoDmsModule } from './connectors/ecodms/ecodms.module';
import { GembaDocsModule } from './connectors/gembadocs/gembadocs.module';

// Main integrations service and controller
import { IntegrationsService } from './integrations.service';
import { IntegrationsController } from './integrations.controller';

/**
 * Integrations Module
 *
 * This module provides comprehensive integration management capabilities:
 *
 * - **Credentials**: Secure storage and management of integration credentials
 * - **Sync**: Manual and scheduled synchronization with external services
 * - **Status**: Health monitoring and statistics for all integrations
 * - **Jobs**: Background job processing for sync operations
 * - **Connectors**: API connectors for external services
 *
 * Supported Integration Types:
 * - PLENTYONE: ERP/E-commerce system integration (orders, stock, statistics)
 * - ZULIP: Team chat/messaging (messages, streams, users)
 * - TODOIST: Task management (tasks, projects, labels)
 * - FREESCOUT: Helpdesk/ticketing
 * - NEXTCLOUD: File storage and collaboration
 * - ECODMS: Document management
 * - GEMBADOCS: Audit and documentation
 *
 * Security:
 * - All credentials are encrypted using AES-256-GCM
 * - Secrets are never logged or exposed in API responses (except when explicitly requested)
 * - Access controlled via INTEGRATIONS_VIEW and INTEGRATIONS_MANAGE permissions
 *
 * API Endpoints (Phase 3):
 * - GET /integrations - Overview of all integrations
 * - GET /integrations/:type/status - Status of specific integration
 * - GET /integrations/:type/health - Health check
 * - /integrations/plentyone/* - PlentyONE specific endpoints
 * - /integrations/zulip/* - ZULIP specific endpoints
 * - /integrations/todoist/* - Todoist specific endpoints
 */
@Module({
  imports: [
    // Core integration infrastructure
    CredentialsModule,
    SyncModule,
    StatusModule,
    JobsModule,

    // API Connector modules (Phase 3)
    PlentyoneModule,
    ZulipModule,
    TodoistModule,
    FreeScoutModule,
    NextcloudModule,
    EcoDmsModule,
    GembaDocsModule,
  ],
  controllers: [IntegrationsController],
  providers: [IntegrationsService],
  exports: [
    // Core modules
    CredentialsModule,
    SyncModule,
    StatusModule,
    JobsModule,

    // Connector modules
    PlentyoneModule,
    ZulipModule,
    TodoistModule,
    FreeScoutModule,
    NextcloudModule,
    EcoDmsModule,
    GembaDocsModule,

    // Service for external use
    IntegrationsService,
  ],
})
export class IntegrationsModule {}
