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

/**
 * <p>
 * <p>
 * https://console.bce.baidu.com/support/?_=1740219852952&timestamp=1740325062124#/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%2Fdriving_license&method=post
 * 驾驶证识别
 */

@Component
@Slf4j
@CustomPath("unifiedValidPeriod")
public class BMixedMultiVehicleHandle extends BaiduBaseHandle<BMixedMultiVehicleRequest, BLicensePlateResp> {


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

    @Override
    public String check(BMixedMultiVehicleRequest bVehicleLicenseRequest) {

        if (checkNotTrueFalse(bVehicleLicenseRequest.getDetectDirection())) {
            return "detectDirection 必须传 " + ApiConstants.trueOrFalse + ",false：不进行图像方向自动矫正, true: 开启图像方向自动矫正功能，可对旋转 90/180/270 度的图片进行自动矫正并识别";
        }

        if (checkNotFrontBack(bVehicleLicenseRequest.getUnified())) {
            return "unified 必须传 " + ApiConstants.frontOrback + ",对输出字段进行归一化处理，将新/老版行驶证的“注册登记日期/注册日期”统一为”注册日期“进行输出";
        }

        return checkImageUri(bVehicleLicenseRequest);
    }

    @Override
    public String getContent(BMixedMultiVehicleRequest bUnifiedValidPeriodRequest) {
        StringBuffer sb = getImageContent(bUnifiedValidPeriodRequest);
        if (StringUtils.isNotBlank(bUnifiedValidPeriodRequest.getDetectDirection())) {
            sb.append("&detect_direction=").append(bUnifiedValidPeriodRequest.getDetectDirection());
        }
        if (StringUtils.isNotBlank(bUnifiedValidPeriodRequest.getUnified())) {
            sb.append("&unified=").append(bUnifiedValidPeriodRequest.getUnified());
        }
        return sb.toString();
    }
}
