package com.docus.server.rpc.impl;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.docus.server.rpc.MzZyyShouMaService;
import com.docus.server.rpc.dto.MzZyyShouMaMedicalDocumentFileForBase64Dto;
import com.docus.server.rpc.dto.MzZyyShouMaMedicalDocumentInfoDto;
import com.docus.server.rpc.dto.MzZyyShouMaQueryMedicalDocumentInfoDto;
import com.docus.server.util.TableJsonRead;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author YongBin Wen
 * @date 2025/3/18 9:27
 */
@Service
@Slf4j
public class MzZyyShouMaServiceImpl implements MzZyyShouMaService {
    final String configPath = "data-config";
    final String configName = "mzzyy-ws-config";

    @Override
    public MzZyyShouMaMedicalDocumentInfoDto queryMedicalDocumentInfoList(MzZyyShouMaQueryMedicalDocumentInfoDto dto) {
        TableJsonRead jsonReader = new TableJsonRead();
        JSONObject configOjb = jsonReader.Read(configPath, configName, JSONObject.class);
        JSONObject shouMaConfig = configOjb.getJSONObject("shouMa");
        String documentInfoListUrl = shouMaConfig.getString("documentInfoListUrl");
        String bodyString = JSON.toJSONString(dto);
        String resp = HttpUtil.post(documentInfoListUrl, bodyString);
        return JSON.parseObject(resp, MzZyyShouMaMedicalDocumentInfoDto.class);
    }

    @Override
    public MzZyyShouMaMedicalDocumentFileForBase64Dto getMedicalDocumentFileForBase64(String reportNo) {
        TableJsonRead jsonReader = new TableJsonRead();
        JSONObject configOjb = jsonReader.Read(configPath, configName, JSONObject.class);
        JSONObject shouMaConfig = configOjb.getJSONObject("shouMa");
        String documentFileForBase64Url = shouMaConfig.getString("documentFileForBase64Url");
        String urlString = documentFileForBase64Url + "?reportNo=" + reportNo;
        String resp = HttpUtil.get(urlString);
        return JSON.parseObject(resp, MzZyyShouMaMedicalDocumentFileForBase64Dto.class);
    }
}
