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

import com.aliyun.facebody20200910.models.ExecuteServerSideVerificationRequest;
import com.aliyun.facebody20200910.models.ExecuteServerSideVerificationResponse;
import com.aliyun.teautil.models.RuntimeOptions;
import com.heyu.api.alibaba.AlibabaBaseHandle;
import com.heyu.api.alibaba.request.facebody.AExecuteServerSideVerificationRequest;
import com.heyu.api.data.annotation.QPS;
import com.heyu.api.data.utils.StringUtils;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/***
 * https://next.api.aliyun.com/api/facebody/2020-09-10/ExecuteServerSideVerification?RegionId=cn-shanghai&tab=DEMO&lang=JAVA
 * 人脸核身服务端
 *
 * ExecuteServerSideVerification
 */
@Component
@QPS(2)
public class AExecuteServerSideVerificationHandle extends AlibabaBaseHandle<AExecuteServerSideVerificationRequest, ExecuteServerSideVerificationResponse> {

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

    @Override
    public String check(AExecuteServerSideVerificationRequest p) {

        if (StringUtils.isBlank(p.getRealName())) {
            return "realName 真实姓名不能为空";
        }

        if (StringUtils.isBlank(p.getIdCardNumber())) {
            return "idCardNumber 身份证号不能为空";
        }


        return checkUrlBase64(p);
    }
    @Override
    public ExecuteServerSideVerificationResponse run(AExecuteServerSideVerificationRequest ap, RuntimeOptions runtime) throws Exception {
        ExecuteServerSideVerificationRequest executeServerSideVerificationRequest = new ExecuteServerSideVerificationRequest();
        executeServerSideVerificationRequest.setCertificateName(ap.getRealName());
        executeServerSideVerificationRequest.setCertificateNumber(ap.getIdCardNumber());
        executeServerSideVerificationRequest.setFacialPictureData(ap.getImageBase64());
        executeServerSideVerificationRequest.setFacialPictureUrl(ap.getImageUrl());
        executeServerSideVerificationRequest.setSceneType(ap.getSceneType());

        java.util.Map<String, String> headers = new java.util.HashMap<>();
        return client.executeServerSideVerificationWithOptions(executeServerSideVerificationRequest, headers, runtime);

    }
}
