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


import com.heyu.api.data.constants.ApiConstants;
import com.heyu.api.data.utils.StringUtils;
import com.heyu.api.baidu.BaiduBaseHandle;
import com.heyu.api.baidu.request.educational.BPenRequest;
import com.heyu.api.baidu.response.educational.BPenResp;
import org.springframework.stereotype.Component;

/***
 *
 *
 * https://console.bce.baidu.com/support/?_=1740575657628&timestamp=1740630425717#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E6%95%99%E8%82%B2%E5%9C%BA%E6%99%AFOCR&api=rest%2F2.0%2Focr%2Fv1%2Fpen&method=post
 *
 *词典笔文字识别
 *
 */
@Component
public class BPenHandle extends BaiduBaseHandle<BPenRequest, BPenResp> {


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

    @Override
    public String check(BPenRequest bPenRequest) {
        if (!ApiConstants.bigOrSmall.containsKey(bPenRequest.getRecognizeGranularity())) {
            return "recognizeGranularity 必须为 " + ApiConstants.bigOrSmall + ", 是否定位单字符位置";
        }

        if (checkNotTrueFalse(bPenRequest.getDetectDirection())) {
            return "detectDirection 必须为 " + trueOrFalse + ", 是否检测图像朝向，默认不检测";
        }
        if (checkNotTrueFalse(bPenRequest.getProbability())) {
            return "probability 必须为 " + trueOrFalse + ",是否返回识别结果中每一行的置信度 ";

        }
        return checkPdf(bPenRequest);
    }

    @Override
    public String getContent(BPenRequest bPenRequest) {
        StringBuffer sb = getPdfContent(bPenRequest);
        if (StringUtils.isNotBlank(bPenRequest.getRecognizeGranularity())) {
            sb.append("&recognize_granularity=").append(bPenRequest.getRecognizeGranularity());
        }
        if (StringUtils.isNotBlank(bPenRequest.getDetectDirection())) {
            sb.append("&detect_direction=").append(bPenRequest.getDetectDirection());
        }


        if (StringUtils.isNotBlank(bPenRequest.getProbability())) {
            sb.append("&probability=").append(bPenRequest.getProbability());
        }

        return sb.toString();
    }
}
