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


import com.alibaba.fastjson.JSON;
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.BAccurateBasicRequest;
import com.heyu.api.baidu.response.common.BAccurateBasicResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * https://console.bce.baidu.com/support/?_=1740219852952&timestamp=1740220055846#/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%2Faccurate_basic&method=post
 * <p>
 * 通用文字识别（高精度。
 */
@Component
@Slf4j
@CustomPath("accurateBasic")
public class BAccurateBasicHandle extends BaiduBaseHandle<BAccurateBasicRequest, BAccurateBasicResp> {


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

    @Override
    public String check(BAccurateBasicRequest bAccurateBasicRequest) {
        if (!ApiConstants.suportLanguage.containsKey(bAccurateBasicRequest.getLanguageType())) {
            return "language_type不正确，目前只支持 " + JSON.toJSONString(ApiConstants.suportLanguage);
        }
        if(!ApiConstants.trueOrFalse.contains(bAccurateBasicRequest.getDetectDirection())){
            return "Detect_direction值是true or false ";
        }

        if(!ApiConstants.trueOrFalse.contains(bAccurateBasicRequest.getParagraph())){
            return "paragraph值是true or false ";
        }

        if(!ApiConstants.trueOrFalse.contains(bAccurateBasicRequest.getProbability())){
            return "probability值是true or false ";
        }
        return checkOfd(bAccurateBasicRequest);
    }


    @Override
    public String getContent(BAccurateBasicRequest bAccurateBasicRequest) {
        StringBuffer sb = getOfdContent(bAccurateBasicRequest);
        if (StringUtils.isNotBlank(bAccurateBasicRequest.getDetectDirection())) {
            sb.append("&detect_direction=" + bAccurateBasicRequest.getDetectDirection());
        }
        if (StringUtils.isNotBlank(bAccurateBasicRequest.getParagraph())) {
            sb.append("&paragraph=" + bAccurateBasicRequest.getParagraph());
        }
        if (StringUtils.isNotBlank(bAccurateBasicRequest.getProbability())) {
            sb.append("&probability=" + bAccurateBasicRequest.getProbability());
        }
        return sb.toString();
    }
}
