package com.heyu.api.alibaba.handle.imagerecog;


import com.aliyun.imagerecog20190930.models.EvaluateCertificateQualityRequest;
import com.aliyun.imagerecog20190930.models.EvaluateCertificateQualityResponse;
import com.aliyun.teautil.models.RuntimeOptions;
import com.heyu.api.data.annotation.CustomPath;
import com.heyu.api.data.utils.StringUtils;
import com.heyu.api.alibaba.AlibabaBaseHandle;
import com.heyu.api.alibaba.request.imagerecog.AEvaluateCertificateQualityRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * https://next.api.aliyun.com/api/imageaudit/2019-12-30/ScanText
 * <p>
 * 证件照质量审核
 *
 * EvaluateCertificateQuality
 */
@Component
@Slf4j
@CustomPath("evaluateCertificate")
public class AEvaluateCertificateQualityHandle extends AlibabaBaseHandle<AEvaluateCertificateQualityRequest, EvaluateCertificateQualityResponse> {


    @Autowired
    private com.aliyun.imagerecog20190930.Client client;


    private List<String> checkSuport = Arrays.asList("IDCard", "BusinessLicense");


    @Override
    public String check(AEvaluateCertificateQualityRequest aEvaluateCertificateQualityRequest) {
        if (StringUtils.isBlank(aEvaluateCertificateQualityRequest.getType())) {
            return "请传type";
        }
        if (!checkSuport.contains(aEvaluateCertificateQualityRequest.getType())) {
            return "请传IDCard或BusinessLicense，IDCard表示身份证,BusinessLicense表示电子执照";
        }
        return checkUrlBase64(aEvaluateCertificateQualityRequest);
    }


    @Override
    public EvaluateCertificateQualityResponse run(AEvaluateCertificateQualityRequest aEvaluateCertificateQualityRequest, RuntimeOptions runtime) throws Exception {
        EvaluateCertificateQualityRequest evaluateCertificateQualityRequest = new EvaluateCertificateQualityRequest();
        evaluateCertificateQualityRequest.setType(aEvaluateCertificateQualityRequest.getType());
        evaluateCertificateQualityRequest.setImageURL(aEvaluateCertificateQualityRequest.getImageUrl());
        // 复制代码运行请自行打印 API 的返回值
        return client.evaluateCertificateQualityWithOptions(evaluateCertificateQualityRequest, runtime);
    }
}
