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

import com.heyu.api.data.annotation.CustomPath;
import com.heyu.api.data.utils.StringUtils;
import com.heyu.api.baidu.BaiduBaseHandle;
import com.heyu.api.baidu.request.financial.BMultipleInvoiceRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * https://console.bce.baidu.com/support/?_=1740494347073&timestamp=1740494448399#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E8%B4%A2%E5%8A%A1%E7%A5%A8%E6%8D%AEOCR&api=rest%2F2.0%2Focr%2Fv1%2Fmultiple_invoice&method=post
 */
@Component
@Slf4j
@CustomPath("multipleInvoice")
public class BMultipleInvoiceHandle extends BaiduBaseHandle<BMultipleInvoiceRequest, Map> {
    @Override
    public String getUri() {
        return "/rest/2.0/ocr/v1/multiple_invoice";
    }

    @Override
    public String check(BMultipleInvoiceRequest bMultipleInvoiceRequest) {
        if (checkNotTrueFalse(bMultipleInvoiceRequest.getVerifyParameter())) {
            return "verifyParameter必须为" + trueOrFalse + ", 是否开启验真";
        }
        if (checkNotTrueFalse(bMultipleInvoiceRequest.getProbability())) {
            return "probability必须为" + trueOrFalse + ",是否返回字段置信度";
        }
        if (checkNotTrueFalse(bMultipleInvoiceRequest.getLocation())) {
            return "location 必须为" + trueOrFalse + ",是否返回字段位置坐标";
        }
        return checkOfd(bMultipleInvoiceRequest);
    }

    @Override
    public String getContent(BMultipleInvoiceRequest bMultipleInvoiceRequest) {
        StringBuffer sb = getOfdContent(bMultipleInvoiceRequest);
        if (StringUtils.isNotBlank(bMultipleInvoiceRequest.getVerifyParameter())) {
            sb.append("&verify_parameter=").append(bMultipleInvoiceRequest.getVerifyParameter());
        }
        if (StringUtils.isNotBlank(bMultipleInvoiceRequest.getProbability())) {
            sb.append("&probability=").append(bMultipleInvoiceRequest.getProbability());
        }
        if (StringUtils.isNotBlank(bMultipleInvoiceRequest.getLocation())) {
            sb.append("&location=").append(bMultipleInvoiceRequest.getLocation());
        }
        return sb.toString();
    }
}
