import { Module } from '@nestjs/common';
import { FactsModule } from '../facts/facts.module';
import { SyncController } from './sync.controller';
import { SyncService } from './sync.service';
import { PullStrategyRegistry } from './adapters/adapter.registry';
import { MockPullStrategy } from './adapters/mock-pull.adapter';
import { ColdImportService } from './cold-import/cold-import.service';
import { ClickHouseSourceService } from './cold-import/clickhouse-source.service';
import { PipelineModule } from './pipeline/pipeline.module';
import { PipelineDispatcher } from './pipeline/pipeline-dispatcher.service';
import { AssemblerModule } from './assembler/assembler.module';
import { TransformsModule } from './transforms/transforms.module';
import { PullOrchestrator } from './pull/pull.orchestrator';
import { ReconcileOrchestrator } from './reconcile/reconcile.orchestrator';
import { PushController } from './push/push.controller';
import { PushReceiverService } from './push/push-receiver.service';
import { HmacVerifier } from './push/hmac-verifier.service';

/**
 * SyncModule — 数据接入主模块。
 *
 * 三入口 + 共享下游:
 *   入口:
 *     - ColdImportService(从目录读 CSV/JSON 文件)
 *     - PullOrchestrator + ReconcileOrchestrator(HTTP 周期拉 / 时间窗对账,经 PullStrategy adapter)
 *     - PushReceiverService(HTTP webhook 收宿主推送,经 HmacVerifier 验签)
 *   共享:
 *     - PullStrategyRegistry(pull/reconcile 共享 adapter,目前注册了 MockPullStrategy)
 *     - PipelineDispatcher(三入口共享:canonical rows → transaction + fact)
 *     - AssemblerModule(raw → canonical;真实 HTTP adapter 才需要;mock/push 跳过)
 *     - PipelineModule(synthesizer + parser pipeline)
 */
@Module({
  imports: [FactsModule, AssemblerModule, TransformsModule, PipelineModule],
  controllers: [SyncController, PushController],
  providers: [
    SyncService,
    PullStrategyRegistry,
    MockPullStrategy,
    ColdImportService,
    ClickHouseSourceService,
    PipelineDispatcher,
    PullOrchestrator,
    ReconcileOrchestrator,
    PushReceiverService,
    HmacVerifier,
  ],
  exports: [
    SyncService,
    PullStrategyRegistry,
    ColdImportService,
    PullOrchestrator,
    ReconcileOrchestrator,
    PushReceiverService,
    PipelineDispatcher,
    AssemblerModule,
    TransformsModule,
    PipelineModule,
  ],
})
export class SyncModule {}
