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


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

/**
 * https://console.bce.baidu.com/support/?_=1740219852952&timestamp=1740325926517#/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%2Flicense_plate&method=post
 * <p>
 * 车牌识别
 */
@Component
@Slf4j
@CustomPath("licensePlate")
public class BLicensePlateHandle extends BaiduBaseHandle<BLicensePlateRequest, BLicensePlateResp> {
    @Override
    public String getUri() {
        return "/rest/2.0/ocr/v1/license_plate";
    }

    @Override
    public String check(BLicensePlateRequest bLicensePlateRequest) {
        if (checkNotTrueFalse(bLicensePlateRequest.getMultiDetect())) {
            return "multiDetect必须为" + trueOrFalse + ", 是否检测多张车牌，默认为false，当置为true的时候可以对一张图片内的多张车牌进行识别";
        }
        if (checkNotTrueFalse(bLicensePlateRequest.getMultiScale())) {
            return "multiScale 必须为" + trueOrFalse + ", 在高拍等车牌较小的场景下可开启，默认为false，当置为true时，能够提高对较小车牌的检测和识别。";
        }

        if (checkNotTrueFalse(bLicensePlateRequest.getDetectComplete())) {
            return "detectComplete 必须为" + trueOrFalse + ",是否开启车牌遮挡检测功能";
        }
        if (checkNotTrueFalse(bLicensePlateRequest.getDetectRisk())) {

            return "detectRisk 必须为 " + trueOrFalse + ",是否开启车牌PS检测功能";
        }

        return checkImageUri(bLicensePlateRequest);
    }

    @Override
    public String getContent(BLicensePlateRequest bLicensePlateRequest) {
        StringBuffer sb = getImageContent(bLicensePlateRequest);
        if (StringUtils.isNotBlank(bLicensePlateRequest.getMultiDetect())) {
            sb.append("&multi_detect=" + bLicensePlateRequest.getMultiDetect());
        }
        if (StringUtils.isNotBlank(bLicensePlateRequest.getMultiScale())) {
            sb.append("&multi_scale=" + bLicensePlateRequest.getMultiScale());
        }
        if (StringUtils.isNotBlank(bLicensePlateRequest.getDetectComplete())) {
            sb.append("&detect_complete=" + bLicensePlateRequest.getDetectComplete());
        }
        if (StringUtils.isNotBlank(bLicensePlateRequest.getDetectRisk())) {
            sb.append("&detect_risk=" + bLicensePlateRequest.getDetectRisk());
        }


        return sb.toString();
    }
}
