import { Module } from '@nestjs/common';
import { AiProviderService } from './core/ai-provider.service';
import { InvocationRecorderService } from './core/invocation-recorder.service';
import { PromptCacheService } from './core/prompt-cache.service';
import { SafetyGateService } from './core/safety-gate.service';
import { AiCallRunnerService } from './ai-call-runner.service';
import { DraftPlanScriptCall } from './calls/draft-plan-script/call';
import { DraftPlanScriptSkillRegistry } from './calls/draft-plan-script/skill-registry.service';
import { DraftPlanSummaryCall } from './calls/draft-plan-summary/call';
import { PlanScriptOrchestrator } from './orchestrators/plan-script.orchestrator';
import { PlanSummaryOrchestrator } from './orchestrators/plan-summary.orchestrator';
import { PlanModule } from '../plan/plan.module';

/**
 * AiModule — harness 入口。
 *
 * 分层:
 *   core/             基建(provider 工厂、缓存、安全门、调用记录)
 *   calls/            一个目录一个 AiCall(prompt + schema + safety rules + fallback)
 *   orchestrators/    业务编排(从 DB 装 input → runner.run → 落业务表)
 *   ai-call-runner    harness 统一执行器(任何 AiCall 都走这里)
 *
 * 加新 AiCall 步骤:
 *   1. calls/<call-key>/ 下放 prompt.ts + schema.ts + input.types.ts + call.ts
 *   2. 在本 module providers + exports 注册
 *   3. 在 orchestrators/ 下加一个业务编排(读 DB、装 input、调 runner、写业务表)
 *
 * 加新 orchestrator(如 plan-summary)同样套这个模板。
 */
@Module({
  imports: [PlanModule], // 给 PlanSummaryOrchestrator 用 ChainComposerService
  providers: [
    // core
    AiProviderService,
    InvocationRecorderService,
    PromptCacheService,
    SafetyGateService,
    // harness
    AiCallRunnerService,
    // AI calls
    DraftPlanScriptCall,
    DraftPlanScriptSkillRegistry, // scan & cache draft-plan-script/skills/**​/SKILL.md
    DraftPlanSummaryCall,
    // orchestrators
    PlanScriptOrchestrator,
    PlanSummaryOrchestrator,
  ],
  exports: [
    // 对外暴露 orchestrator(业务方调用入口)+ runner(高级使用 / eval CLI)
    PlanScriptOrchestrator,
    PlanSummaryOrchestrator,
    AiCallRunnerService,
    AiProviderService,
    // 实时坐席辅助教练复用:skills 注册表(组装 Qwen instructions)
    DraftPlanScriptSkillRegistry,
  ],
})
export class AiModule {}
