package com.emoon.tongue.service.impl;

import com.emoon.tongue.domain.vo.TongueDiagnosisDetailVo;
import com.emoon.tongue.domain.vo.TongueDiagnosisInfo;
import com.emoon.tongue.service.ITongueAiDiagnosisService;
import com.emoon.tongue.service.ITongueDiagnosisService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 舌诊AI诊断服务实现类（Mock版本）
 *
 * @author destiny
 * @date 2025-12-11
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class TongueAiDiagnosisServiceImpl implements ITongueAiDiagnosisService {

    private final ITongueDiagnosisService tongueDiagnosisService;

    @Override
    public TongueDiagnosisInfo performDiagnosis(String regNumber, String projectId) {
        log.info("开始进行舌诊AI诊断，挂号单号: {}, 医院编码: {}", regNumber, projectId);

        try {
            // 获取舌诊详情（包含图片URL和患者信息）
            TongueDiagnosisDetailVo detail = tongueDiagnosisService.getDiagnosisDetail(regNumber, projectId);

            if (detail == null || detail.getTongueImage() == null) {
                log.warn("未找到舌诊记录或图片URL为空，挂号单号: {}", regNumber);
                return null;
            }

            // 使用TongueDiagnosisInfo的generateMockResult方法生成诊断结果
            TongueDiagnosisInfo result = TongueDiagnosisInfo.generateMockResult();

            log.info("舌诊AI诊断完成，置信度: {}%", result.getOverallConfidence());
            return result;

        } catch (Exception e) {
            log.error("舌诊AI诊断异常", e);
            throw new RuntimeException("AI诊断失败: " + e.getMessage());
        }
    }
}
