package com.heyu.api.controller.medical;

import com.heyu.api.baidu.handle.medical.BMedicalSummaryDiagnosisHandle;
import com.heyu.api.baidu.request.medical.BMedicalSummaryDiagnosisRequest;
import com.heyu.api.baidu.response.medical.BMedicalSummaryDiagnosisResp;
import com.heyu.api.controller.BaseController;
import com.heyu.api.data.annotation.CacheResult;
import com.heyu.api.data.annotation.NotIntercept;
import com.heyu.api.data.utils.ApiR;
import com.heyu.api.data.utils.R;
import com.heyu.api.resp.medical.MedicalSummaryDiagnosisResp;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;



/***
 * https://console.bce.baidu.com/support/?_=1740575657628&timestamp=1740582137426#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E5%8C%BB%E7%96%97%E7%A5%A8%E6%8D%AEOCR&api=%2Frest%2F2.0%2Focr%2Fv1%2Fmedical_summary_diagnosis&method=post
 *
 *
 * 诊断证明识别
 *
 *接口描述
 * 支持识别全国各地各医院诊断证明的姓名、性别、年龄
 *
 */
@Slf4j
@RestController
@RequestMapping("/medical")
@NotIntercept
public class MedicalSummaryDiagnosisController extends BaseController {


    @Autowired
    private BMedicalSummaryDiagnosisHandle bMedicalSummaryDiagnosisHandle;


    @RequestMapping("/summaryDiagnosis")
    @CacheResult
    public R summaryDiagnosis(BMedicalSummaryDiagnosisRequest req) {

        List<MedicalSummaryDiagnosisResp> respList = new ArrayList<>();

        ApiR<BMedicalSummaryDiagnosisResp> bR = bMedicalSummaryDiagnosisHandle.handle(req);
        if (bR.isSuccess()) {
            BMedicalSummaryDiagnosisResp bMedicalSummaryDiagnosisResp = bR.getData();
            List<BMedicalSummaryDiagnosisResp.WordsResultDTO> wordsResult = bMedicalSummaryDiagnosisResp.getWordsResult();

            if (CollectionUtils.isNotEmpty(wordsResult)) {
                for (BMedicalSummaryDiagnosisResp.WordsResultDTO resultDTO : wordsResult) {
                    MedicalSummaryDiagnosisResp medicalSummaryDiagnosisResp = new MedicalSummaryDiagnosisResp();
                    medicalSummaryDiagnosisResp.setWord(resultDTO.getWord());
                    medicalSummaryDiagnosisResp.setWordName(resultDTO.getWordName());
                    respList.add(medicalSummaryDiagnosisResp);
                }

            }

            return R.ok().setData(respList);

        }

        return R.error(bR.getErrorMsg());
    }
}