import { Module } from '@nestjs/common';
import { PlanController } from './plan.controller';
import { PlanService } from './plan.service';
import { AssignmentController } from './assignment.controller';
import { PlanAssignmentService } from './plan-assignment.service';
import { AgentRosterService } from './agent-roster.service';
import { AssignmentProposalService } from './assignment-proposal.service';
import { CohortAttributesService } from './cohort-attributes.service';
import { ExecutionService } from './execution.service';
import { ExecutionCallbackService } from './execution-callback.service';
import { RecycleSchedulerService } from './recycle-scheduler.service';
import { AssignmentExpiryScheduler } from './assignment-expiry.scheduler';
import { PlanEngineService } from './engine/plan-engine.service';
import { ChainComposerService } from './engine/chain-composer.service';
import { TreatmentInitiationRecallScenario } from './engine/scenarios/treatment-initiation-recall.scenario';
import { RecallDebugController } from './recall-debug/recall-debug.controller';
import { PlanLabelService } from './plan-label.service';
import { RecallDebugService } from './recall-debug/recall-debug.service';

/**
 * v2.1:plan 一期只跑潜在治疗新链召回(treatment_initiation_recall)。
 * 链已完成召回(aftercare)留后续,文件已删。
 */
@Module({
  // ⚠️⚠️ **AssignmentController 必须排在 PlanController 之前**,顺序不是随意的。
  //   两者的路由前缀都是 `plans`,而 PlanController 有一条裸 `@Get(':id')`(plan.controller:94)。
  //   Nest 按**注册顺序**匹配 → 反过来的话 `GET /plans/assignments` 会被当成
  //   `GET /plans/:id`(id='assignments'),然后去查一个不存在的 plan,
  //   报的还是 Prisma 的 uuid 解析错(90000),完全看不出是路由撞了。
  //   实测踩过一次。同类先例见 plan.controller:80 的 `doctors` 那条注释。
  controllers: [AssignmentController, PlanController, RecallDebugController],
  providers: [
    PlanService,
    PlanAssignmentService,
    AgentRosterService,
    AssignmentProposalService,
    CohortAttributesService,
    ExecutionService,
    ExecutionCallbackService,
    RecycleSchedulerService,
    AssignmentExpiryScheduler,
    PlanEngineService,
    ChainComposerService,
    TreatmentInitiationRecallScenario,
    RecallDebugService,
    PlanLabelService,
  ],
  // MCP 的主管工具直接用这两个 service(条件注册,见 mcp-server.factory)
  exports: [PlanService, PlanLabelService, PlanAssignmentService, AgentRosterService, AssignmentProposalService, CohortAttributesService, ExecutionService, ExecutionCallbackService, PlanEngineService, ChainComposerService],
})
export class PlanModule {}
