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

/**
 * https://console.bce.baidu.com/support/?_=1740219852952&timestamp=1740300649701#/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%2Fsmart_struct&method=post
 * 智能结构化
 */
@Component
@Slf4j
@CustomPath("smartStruct")
public class BSmartStructHandle extends BaiduBaseHandle<ASmartStructRequest, ASmartStructResp> {
    @Override
    public String getUri() {
        return "/rest/2.0/ocr/v1/smart_struct";
    }

    @Override
    public String check(ASmartStructRequest aSmartStructRequest) {
        if (!ApiConstants.trueOrFalse.contains(aSmartStructRequest.getReturnRelation())) {
            return "returnRelation 仅能传" + ApiConstants.trueOrFalse + ",是否返回结构化对应关系及单文本行结果";
        }
        return checkPdf(aSmartStructRequest);
    }

    @Override
    public String getContent(ASmartStructRequest aSmartStructRequest) {
        StringBuffer sb = getPdfContent(aSmartStructRequest);
        if (StringUtils.isNotBlank(aSmartStructRequest.getReturnRelation())) {
            sb.append("&return_relation=").append(aSmartStructRequest.getReturnRelation());
        }
        return sb.toString();
    }
}
