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


import com.heyu.api.data.annotation.CustomPath;
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.common.ANumbersRequest;
import com.heyu.api.baidu.response.common.ANumbersResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * https://console.bce.baidu.com/support/?_=1740219852952&timestamp=1740299353970#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E9%80%9A%E7%94%A8%E5%9C%BA%E6%99%AFOCR&api=rest%2F2.0%2Focr%2Fv1%2Fnumbers&method=post
 * <p>
 * <p>
 * 数字识别
 */
@Component
@Slf4j
@CustomPath("numbers")
public class BNumbersHandle extends BaiduBaseHandle<ANumbersRequest, ANumbersResp> {
    @Override
    public String getUri() {
        return "/rest/2.0/ocr/v1/numbers";
    }

    @Override
    public String check(ANumbersRequest aNumbersRequest) {
        if (!ApiConstants.bigOrSmall.containsKey(aNumbersRequest.getRecognizeGranularity())) {
            return "recognizeGranularity 仅能传：" + ApiConstants.bigOrSmall + ",是否定位单字符位置";
        }
        if (!ApiConstants.trueOrFalse.contains(aNumbersRequest.getDetectDirection())) {
            return "detectDirection 仅能传：" + ApiConstants.trueOrFalse + ",是否检测图像朝向";
        }
        return checkOfd(aNumbersRequest);
    }

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

        return sb.toString();
    }
}
