package com.heyu.api.baidu.handle.medical;


import com.heyu.api.data.utils.StringUtils;
import com.heyu.api.baidu.BaiduBaseHandle;
import com.heyu.api.baidu.request.medical.BMedicalInvoiceRequest;
import com.heyu.api.baidu.response.medical.BMedicalInvoiceResp;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.TreeMap;

/***
 * https://console.bce.baidu.com/support/?_=1740575657628&timestamp=1740580001377#/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=rest%2F2.0%2Focr%2Fv1%2Fmedical_invoice&method=post
 *
 *医疗发票识别
 */
@Component
public class BMedicalInvoiceHandle extends BaiduBaseHandle<BMedicalInvoiceRequest, BMedicalInvoiceResp> {

    public static Map<String, Object> suport = new TreeMap<>();

    static {
        suport.put("100000", "北京");
        suport.put("200000", "上海");
        suport.put("510000", "广州");
        suport.put("518000", "深圳");
        suport.put("519000", "珠海");
        suport.put("410000", "长沙");
        suport.put("400000", "重庆");
        suport.put("710000", "西安");
        suport.put("300000", "天津");
        suport.put("528000", "佛山");
        suport.put("523000", "东莞");
        suport.put("310000", "杭州");
        suport.put("450000", "郑州");
        suport.put("550000", "贵阳");
        suport.put("116000", "大连");
        suport.put("215000", "苏州");
        suport.put("210000", "南京");
        suport.put("430000", "武汉");
        suport.put("230000", "合肥");
        suport.put("610000", "成都");
        suport.put("50000", "家庄");
    }


    @Override
    public String getUri() {
        return "/rest/2.0/ocr/v1/medical_invoice";
    }

    @Override
    public String check(BMedicalInvoiceRequest bMedicalInvoiceRequest) {
        if (checkNotTrueFalse(bMedicalInvoiceRequest.getLocation())) {
            return "location必须为" + trueOrFalse + ",是否返回字段的位置信息";
        }
        if (checkNotTrueFalse(bMedicalInvoiceRequest.getProbability())) {
            return "probability 必须为" + trueOrFalse + ",是否返回字段识别结果的置信度";
        }
        if (!suport.containsKey(bMedicalInvoiceRequest.getMediQuery())) {
            return "mediQuery必须为" + StringUtils.printMap(suport) + ",医保三目录查询，可选值为对应城市代码，可缺省，当此参数的输入值不为对应城市编码时，即进行全量查询，默认进行全量查询，如不需要进行医保三目录查询，无需添加此参数 ";
        }
        return checkImageUri(bMedicalInvoiceRequest);
    }

    @Override
    public String getContent(BMedicalInvoiceRequest bMedicalInvoiceRequest) {
        StringBuffer sb = getImageContent(bMedicalInvoiceRequest);
        if (StringUtils.isNotBlank(bMedicalInvoiceRequest.getLocation())) {
            sb.append("&location=" + bMedicalInvoiceRequest.getLocation());
        }
        if (StringUtils.isNotBlank(bMedicalInvoiceRequest.getProbability())) {
            sb.append("&probability=" + bMedicalInvoiceRequest.getProbability());
        }
        if (StringUtils.isNotBlank(bMedicalInvoiceRequest.getMediQuery())) {
            sb.append("&medi_query=" + bMedicalInvoiceRequest.getMediQuery());
        }
        return sb.toString();
    }
}
