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


import com.heyu.api.baidu.BaiduBaseHandle;
import com.heyu.api.baidu.request.certificate.BMultiIdcardRequest;
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=1740302247547#/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%2Fmulti_idcard&method=post
 * <p>
 * <p>
 * 身份证混贴识别
 */

@Component
@Slf4j
@CustomPath("multiIdcard")
public class BMultiIdcardHandle extends BaiduBaseHandle<BMultiIdcardRequest, Map> {

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

    @Override
    public String check(BMultiIdcardRequest bMultiIdcardRequest) {
        if (checkNotTrueFalse(bMultiIdcardRequest.getDetectRisk())) {
            return "detectRisk 仅能传 " + ApiConstants.trueOrFalse + ",是否开启身份证风险类型(身份证复印件、临时身份证、身份证翻拍、修改过的身份证)功能";
        }

        if (checkNotTrueFalse(bMultiIdcardRequest.getDetectQuality())) {
            return "detectQuality 仅能传 " + ApiConstants.trueOrFalse + ",是否开启身份证质量类型(边框/四角不完整、头像或关键字段被遮挡/马赛克)检测功能";
        }


        if (checkNotTrueFalse(bMultiIdcardRequest.getDetectPhoto())) {
            return "detectPhoto 仅能传 " + ApiConstants.trueOrFalse + ",是否检测头像内容";
        }

        if (checkNotTrueFalse(bMultiIdcardRequest.getDetectCard())) {
            return "detectRisk 仅能传 " + ApiConstants.trueOrFalse + ",是否检测身份证进行裁剪";
        }

        return checkImageUri(bMultiIdcardRequest);
    }

    @Override
    public String getContent(BMultiIdcardRequest bMultiIdcardRequest) {
        StringBuffer sb = getImageContent(bMultiIdcardRequest);
        if (StringUtils.isNotBlank(bMultiIdcardRequest.getDetectRisk())) {
            sb.append("&detect_risk=").append(bMultiIdcardRequest.getDetectRisk());
        }
        if (StringUtils.isNotBlank(bMultiIdcardRequest.getDetectQuality())) {
            sb.append("&detect_quality=").append(bMultiIdcardRequest.getDetectQuality());
        }
        if (StringUtils.isNotBlank(bMultiIdcardRequest.getDetectPhoto())) {
            sb.append("&detect_photo=").append(bMultiIdcardRequest.getDetectPhoto());
        }
        if (StringUtils.isNotBlank(bMultiIdcardRequest.getDetectCard())) {
            sb.append("&detect_card=").append(bMultiIdcardRequest.getDetectCard());
        }
        return sb.toString();
    }
}
