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


import com.heyu.api.data.utils.StringUtils;
import com.heyu.api.baidu.BaiduBaseHandle;
import com.heyu.api.baidu.request.others.BMeterRequest;
import com.heyu.api.baidu.response.others.BMeterResp;
import org.springframework.stereotype.Component;

/***
 * https://console.bce.baidu.com/support/?_=1740667714316&timestamp=1740667716472#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E5%85%B6%E4%BB%96%E5%9C%BA%E6%99%AFOCR&api=rest%2F2.0%2Focr%2Fv1%2Fmeter&method=post
 *
 * 仪器仪表盘读数识别
 */
@Component
public class BMeterHandle extends BaiduBaseHandle<BMeterRequest, BMeterResp> {
    @Override
    public String getUri() {
        return "/rest/2.0/ocr/v1/meter";
    }

    @Override
    public String check(BMeterRequest bMeterRequest) {
        if (checkNotTrueFalse(bMeterRequest.getProbability())) {
            return "probability 必须为" + trueOrFalse + ", 是否返回每行识别结果的置信度";
        }
        if (checkNotTrueFalse(bMeterRequest.getPolyLocation())) {
            return "polyLocation 必须为 " + trueOrFalse + ",false：只给出识别结果所在长方形位置信息，除了默认的识别文字所在长方形的位置信息，还会给出文字所在区域的最小外接旋转矩形的4个点坐标信息 ";
        }

        return checkImageUri(bMeterRequest);
    }

    @Override
    public String getContent(BMeterRequest bMeterRequest) {
        StringBuffer sb = getImageContent(bMeterRequest);
        if (StringUtils.isNotBlank(bMeterRequest.getProbability())) {
            sb.append("&probability=" + bMeterRequest.getProbability());
        }
        if (StringUtils.isNotBlank(bMeterRequest.getPolyLocation())) {
            sb.append("&polyLocation=" + bMeterRequest.getPolyLocation());
        }
        return sb.toString();
    }
}
