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

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

/**
 * https://console.bce.baidu.com/support/?_=1740411162437&timestamp=1740412723534#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E4%BA%A4%E9%80%9A%E5%9C%BA%E6%99%AFOCR&api=rest%2F2.0%2Focr%2Fv1%2Fwaybill&method=post
 * 快递面单识别
 */
@Component
@Slf4j
@CustomPath("waybill")
public class BWaybillHandle extends BaiduBaseHandle<BWaybillRequest, BWaybillResp> {
    @Override
    public String getUri() {
        return "/rest/2.0/ocr/v1/waybill";
    }

    @Override
    public String check(BWaybillRequest bWaybillRequest) {
        if (checkNotTrueFalse(bWaybillRequest.getIsIdentifyVirtualWaybill())) {
            return "isIdentifyVirtualWaybill必须为" + ApiConstants.trueOrFalse + ", 是否需要识别隐私面单, true：需要识别隐私面单,  false：不识别隐私面单";
        }
        return checkImageUri(bWaybillRequest);
    }

    @Override
    public String getContent(BWaybillRequest bWaybillRequest) {
        StringBuffer sb = getImageContent(bWaybillRequest);
        if (StringUtils.isNotBlank(bWaybillRequest.getIsIdentifyVirtualWaybill())) {
            sb.append("&is_identify_virtual_waybill=").append(bWaybillRequest.getIsIdentifyVirtualWaybill());
        }
        return sb.toString();
    }
}
