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.BWebImageRequest;
import com.heyu.api.baidu.response.common.BWebImageResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * https://console.bce.baidu.com/support/?_=1740219852952&timestamp=1740294053851#/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%2Fwebimage&method=post
 * <p>
 * <p>
 * 通用文字识别（标准含。
 */
@Component
@Slf4j
@CustomPath("general")
public class BWebImageHandle extends BaiduBaseHandle<BWebImageRequest, BWebImageResp> {

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

    @Override
    public String check(BWebImageRequest bWebImageRequest) {
        if (!ApiConstants.trueOrFalse.contains(bWebImageRequest.getDetectDirection())) {
            return "detectDirection仅能传：" + ApiConstants.trueOrFalse + ",是否检测图像朝向，默认不检测，即：false。朝向是指输入图像是正常方向、逆时针旋转90";
        }
        if (!ApiConstants.trueOrFalse.contains(bWebImageRequest.getDetectLanguage())) {
            return "detectLanguage 仅能传" + ApiConstants.trueOrFalse + ",是否检测语言。";
        }
        return checkOfd(bWebImageRequest);
    }

    @Override
    public String getContent(BWebImageRequest bWebImageRequest) {
        StringBuffer sb = getOfdContent(bWebImageRequest);
        if (StringUtils.isNotBlank(bWebImageRequest.getDetectDirection())) {
            sb.append("&detect_direction=" + bWebImageRequest.getDetectDirection());
        }
        if (StringUtils.isNotBlank(bWebImageRequest.getDetectLanguage())) {
            sb.append("&detect_language=" + bWebImageRequest.getDetectLanguage());
        }
        return sb.toString();
    }

}
