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.BPaperCutEduRequest;
import com.heyu.api.baidu.response.educational.BPaperCutEduResp;
import org.springframework.stereotype.Component;

/***
 * https://console.bce.baidu.com/support/?_=1740575657628&timestamp=1740631611089#/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%2Fpaper_cut_edu&method=post
 *
 * 试卷切题识别
 */
@Component
public class BPaperCutEduHandle extends BaiduBaseHandle<BPaperCutEduRequest, BPaperCutEduResp> {
    @Override
    public String getUri() {
        return "/2.0/ocr/v1/paper_cut_edu";
    }

    @Override
    public String check(BPaperCutEduRequest bPaperCutEduRequest) {
        if (!ApiConstants.chnEngOREng.equals(bPaperCutEduRequest.getLanguageType())) {
            return "languageType 必须为" + ApiConstants.chnEngOREng + ", 识别语言类型，默认为 CHN_ENG";
        }

        if (checkNotTrueFalse(bPaperCutEduRequest.getDetectDirection())) {
            return "detectDirection 必须为 " + trueOrFalse + ", 是否检测图像朝向";
        }
        if (!ApiConstants.handwringOnlyOrHandprintMix.containsKey(bPaperCutEduRequest.getWordsType())) {
            return "wordsType 必须为 " + trueOrFalse + ", 识别文字类型";
        }
        return checkPdf(bPaperCutEduRequest);
    }

    @Override
    public String getContent(BPaperCutEduRequest bPaperCutEduRequest) {
        StringBuffer sb = getPdfContent(bPaperCutEduRequest);
        if (StringUtils.isNotBlank(bPaperCutEduRequest.getLanguageType())) {
            sb.append("&language_type=" + bPaperCutEduRequest.getLanguageType());
        }
        if (StringUtils.isNotBlank(bPaperCutEduRequest.getDetectDirection())) {
            sb.append("&detect_direction=" + bPaperCutEduRequest.getDetectDirection());
        }

        if (StringUtils.isNotBlank(bPaperCutEduRequest.getWordsType())) {
            sb.append("&words_type=" + bPaperCutEduRequest.getWordsType());
        }
        return sb.toString();
    }
}
