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


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

/**
 * https://console.bce.baidu.com/support/?_=1740219852952&timestamp=1740306844271#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E5%8D%A1%E8%AF%81OCR&api=rest%2F2.0%2Focr%2Fv1%2Fbankcard&method=post
 * 银行卡识别
 */
@Component
@Slf4j
@CustomPath("bankcard")
public class BBankcardHandle extends BaiduBaseHandle<BBankcardRequest, BBankcardResp> {
    @Override
    public String getUri() {
        return "/rest/2.0/ocr/v1/bankcard";
    }

    @Override
    public String check(BBankcardRequest bBankcardRequest) {
        if (checkNotTrueFalse(bBankcardRequest.getLocation())) {
            return "location必须为" + ApiConstants.trueOrFalse + ",是否返回银行卡号的字段位置坐标";
        }
        if (checkNotTrueFalse(bBankcardRequest.getDetectQuality())) {
            return "detectQuality必须为" + ApiConstants.trueOrFalse + "是否开启银行卡质量类型（清晰模糊、边框/四角不完整）检测功能";
        }
        return checkImageUri(bBankcardRequest);
    }

    @Override
    public String getContent(BBankcardRequest bBankcardRequest) {
        StringBuffer sb = getImageContent(bBankcardRequest);
        if (StringUtils.isNotBlank(bBankcardRequest.getLocation())) {
            sb.append("&location=").append(bBankcardRequest.getLocation());
        }
        if (StringUtils.isNotBlank(bBankcardRequest.getDetectQuality())) {
            sb.append("&detect_quality=").append(bBankcardRequest.getDetectQuality());
        }
        return sb.toString();
    }
}
