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


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

/**
 * https://console.bce.baidu.com/support/?_=1740494347073&timestamp=1740497736043#/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%2Fvat_invoice&method=post
 * <p>
 * 增值税发票识别
 */


@Component
@Slf4j
@CustomPath("vatInvoice")
public class BVatInvoiceHandle extends BaiduBaseHandle<BVatInvoiceRequest, BVatInvoiceResp> {

    @Override
    public String getUri() {
        return "/rest/2.0/ocr/v1/vat_invoice";
    }

    @Override
    public String check(BVatInvoiceRequest bVatInvoiceRequest) {
        if (!ApiConstants.normalOrRoll.contains(bVatInvoiceRequest.getType())) {
            return "type必须为" + ApiConstants.normalOrRoll + ",进行识别的增值税发票类型 , normal: 可识别增值税普票、专票、电子发票 , roll, 可识别增值税卷票";
        }
        if (checkNotTrueFalse(bVatInvoiceRequest.getSealTag())) {
            return "sealTag必须为" + trueOrFalse + ",是否开启印章判断功能，并返回印章内容的识别结果";
        }
        return checkOfd(bVatInvoiceRequest);
    }

    @Override
    public String getContent(BVatInvoiceRequest bVatInvoiceRequest) {
        StringBuffer sb = getOfdContent(bVatInvoiceRequest);
        if (StringUtils.isNotBlank(bVatInvoiceRequest.getType())) {
            sb.append("&type=").append(bVatInvoiceRequest.getType());
        }
        if (StringUtils.isNotBlank(bVatInvoiceRequest.getSealTag())) {
            sb.append("&seal_tag=").append(bVatInvoiceRequest.getSealTag());
        }
        return sb.toString();
    }
}
