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


import com.heyu.api.baidu.BaiduBaseHandle;
import com.heyu.api.baidu.request.traffic.BVehicleLicenseRequest;
import com.heyu.api.data.annotation.CustomPath;
import com.heyu.api.data.constants.ApiConstants;
import com.heyu.api.data.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * https://console.bce.baidu.com/support/?_=1740219852952&timestamp=1740323990690#/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%2Fvehicle_license&method=post
 * <p>
 * <p>
 * 行驶证识别
 */
@Component
@Slf4j
@CustomPath("vehicleLicense")
public class BVehicleLicenseHandle extends BaiduBaseHandle<BVehicleLicenseRequest, Map> {


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

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

        if (checkNotFrontBack(bVehicleLicenseRequest.getVehicleLicenseSide())) {
            return "vehicleLicenseSide 必须传 " + ApiConstants.frontOrback + ",front：正向， back反面";
        }

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

        if (checkNotTrueFalse(bVehicleLicenseRequest.getQualityWarn())) {
            return "qualityWarn 必须为" + ApiConstants.trueOrFalse + ",false：不输出质量告警信息, true : 输出行驶证遮挡、不完整质量告警信息";
        }

        return checkImageUri(bVehicleLicenseRequest);
    }

    @Override
    public String getContent(BVehicleLicenseRequest bVehicleLicenseRequest) {
        StringBuffer sb = getImageContent(bVehicleLicenseRequest);
        if (StringUtils.isNotBlank(bVehicleLicenseRequest.getDetectDirection())) {
            sb.append("&detect_direction=").append(bVehicleLicenseRequest.getDetectDirection());
        }
        if (StringUtils.isNotBlank(bVehicleLicenseRequest.getVehicleLicenseSide())) {
            sb.append("&vehicle_license_side=").append(bVehicleLicenseRequest.getVehicleLicenseSide());
        }
        if (StringUtils.isNotBlank(bVehicleLicenseRequest.getUnified())) {
            sb.append("&unified=").append(bVehicleLicenseRequest.getUnified());
        }
        if (StringUtils.isNotBlank(bVehicleLicenseRequest.getQualityWarn())) {
            sb.append("&quality_warn=").append(bVehicleLicenseRequest.getQualityWarn());
        }
        if (StringUtils.isNotBlank(bVehicleLicenseRequest.getRiskWarn())) {
            sb.append("&risk_warn=").append(bVehicleLicenseRequest.getRiskWarn());
        }
        return sb.toString();
    }
}
