import { Injectable, Logger, NotImplementedException } from '@nestjs/common';
import { Observable } from 'rxjs';
import { AgentKind, type AgentScriptStreamEvent } from '@pac/types';
import { PrismaService } from '../../prisma/prisma.service';
import type { TenantScopeContext } from '../../common/decorators/tenant-scope.decorator';
import { AiGatewayClient } from './ai-gateway.client';

/**
 * AgentService — AI 调用统一入口(经 AI Gateway → Dify)
 *
 * 暂未实施。AI 产物(plan_script / plan_summary / persona feature description)
 * 由 BullMQ 异步队列驱动,接入 Vercel AI SDK 后落地。
 */
@Injectable()
export class AgentService {
  private readonly logger = new Logger(AgentService.name);

  constructor(
    private readonly prisma: PrismaService,
    private readonly gateway: AiGatewayClient,
  ) {}

  async invoke(_input: {
    scope: TenantScopeContext;
    agentKind: AgentKind;
    workflowId: string;
    inputSnapshot: Record<string, unknown>;
    promptTemplate?: string;
    linkedPatientId?: string;
    linkedPersonaId?: string;
    linkedPlanId?: string;
  }): Promise<{ invocationId: string; outputText: string; outputs: Record<string, unknown> }> {
    throw new NotImplementedException('AgentService.invoke 暂未实施,等待 AI Gateway / Vercel AI SDK 接入');
  }

  streamScriptForPlan(
    _scope: TenantScopeContext,
    _planId: string,
    _workflowId?: string,
  ): Observable<AgentScriptStreamEvent> {
    throw new NotImplementedException('AgentService.streamScriptForPlan 暂未实施(异步 BullMQ + AI Gateway)');
  }
}
