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

/**
 * https://console.bce.baidu.com/support/?_=1740219852952&timestamp=1740298492177#/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%2Fseal&method=post
 * <p>
 * <p>
 * 印章识别
 */
@Component
@Slf4j
@CustomPath("seal")
public class BSealHandle extends BaiduBaseHandle<BSealRequest, BSealResp> {
    @Override
    public String getUri() {
        return "/rest/2.0/ocr/v1/seal";
    }

    @Override
    public String check(BSealRequest bSealRequest) {
        if (!ApiConstants.trueOrFalse.contains(bSealRequest.getReturnImage())) {
            return "returnImage 仅能传 " + ApiConstants.trueOrFalse + ",是否返回印章切片图片";
        }
        if (!ApiConstants.trueOrFalse.contains(bSealRequest.getFlattenImage())) {
            return "flattenImage" + ApiConstants.trueOrFalse + ",是否返回印章展平图片";
        }

        return checkOfd(bSealRequest);
    }


    @Override
    public String getContent(BSealRequest bSealRequest) {
        StringBuffer sb = getOfdContent(bSealRequest);
        if (StringUtils.isNotBlank(bSealRequest.getReturnImage())) {
            sb.append("&return_image=" + bSealRequest.getReturnImage());
        }
        if (StringUtils.isNotBlank(bSealRequest.getFlattenImage())) {
            sb.append("&flatten_image=" + bSealRequest.getFlattenImage());
        }
        return sb.toString();
    }


}
