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.BHkMacauTaiwanExitentrypermitRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.TreeMap;

/**
 * https://console.bce.baidu.com/support/?_=1740219852952&timestamp=1740313880415#/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%2Fhk_macau_taiwan_exitentrypermit&method=post
 * <p>
 * <p>
 * 港澳台证件识别
 */
@Component
@Slf4j
@CustomPath("hkMacauTaiwanExitentrypermit")
public class BHkMacauTaiwanExitentrypermitHandle extends BaiduBaseHandle<BHkMacauTaiwanExitentrypermitRequest, Map> {


    public final static Map<String, Object> suportType = new TreeMap<>();

    static {
        suportType.put("hk_mc_passport_front", "港澳通行证正面");
        suportType.put("hk_mc_passport_back", "港澳通行证反面");
        suportType.put("tw_passport_front", "台湾通行证正面");
        suportType.put("tw_passport_back", "台湾通行证反面");
        suportType.put("tw_return_passport_front", "台胞证正面");
        suportType.put("tw_return_passport_back", "台胞证反面");
        suportType.put("hk_mc_return_passport_front", "返乡证正面");
        suportType.put("hk_mc_return_passport_back", "返乡证反面");
    }

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

    @Override
    public String check(BHkMacauTaiwanExitentrypermitRequest bHkMacauTaiwanExitentrypermitRequest) {
        if (!suportType.containsKey(bHkMacauTaiwanExitentrypermitRequest.getExitentrypermitType())) {
            return "exitentrypermitType 的范围是：" + StringUtils.printMap(suportType);
        }
        if (checkNotTrueFalse(bHkMacauTaiwanExitentrypermitRequest.getProbability())) {
            return "probability必须为" + ApiConstants.trueOrFalse;
        }

        if (StringUtils.isBlank(bHkMacauTaiwanExitentrypermitRequest.getLocation())) {
            return "location必须为" + ApiConstants.trueOrFalse;
        }
        return checkPdf(bHkMacauTaiwanExitentrypermitRequest);
    }

    @Override
    public String getContent(BHkMacauTaiwanExitentrypermitRequest bHkMacauTaiwanExitentrypermitRequest) {
        StringBuffer sb = getPdfContent(bHkMacauTaiwanExitentrypermitRequest);
        if (StringUtils.isNotBlank(bHkMacauTaiwanExitentrypermitRequest.getExitentrypermitType())) {
            sb.append("&exitentrypermit_type=").append(bHkMacauTaiwanExitentrypermitRequest.getExitentrypermitType());
        }
        if (StringUtils.isNotBlank(bHkMacauTaiwanExitentrypermitRequest.getProbability())) {
            sb.append("&probability=").append(bHkMacauTaiwanExitentrypermitRequest.getProbability());
        }
        if (StringUtils.isNotBlank(bHkMacauTaiwanExitentrypermitRequest.getLocation())) {
            sb.append("&location=").append(bHkMacauTaiwanExitentrypermitRequest.getLocation());
        }
        return sb.toString();
    }


}
