package com.heyu.api.alibaba.handle.common.text;


import com.aliyun.ocr20191230.models.RecognizeIdentityCardRequest;
import com.aliyun.ocr20191230.models.RecognizeIdentityCardResponse;
import com.aliyun.teautil.models.RuntimeOptions;
import com.heyu.api.data.annotation.CustomPath;
import com.heyu.api.alibaba.AlibabaBaseHandle;
import com.heyu.api.alibaba.request.common.text.ARecognizeIdentityCardRequest;
import com.heyu.api.data.annotation.QPS;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * https://next.api.aliyun.com/api/ocr/2019-12-30/RecognizeIdentityCard
 * <p>
 * 身份证识别
 *
 *
 */
@Component
@Slf4j
@CustomPath("identityCard")
@QPS(2)
public class ARecognizeIdentityCardHandle extends AlibabaBaseHandle<ARecognizeIdentityCardRequest, RecognizeIdentityCardResponse> {

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


    @Override
    public String check(ARecognizeIdentityCardRequest aRecognizeIdentityCardRequest) {
        return checkUrlBase64(aRecognizeIdentityCardRequest);
    }


    @Override
    public RecognizeIdentityCardResponse run(ARecognizeIdentityCardRequest recognizeIdentityCardRequest, RuntimeOptions runtime) throws Exception {
        RecognizeIdentityCardRequest request = new RecognizeIdentityCardRequest();
        request.setImageURL(recognizeIdentityCardRequest.getImageUrl());
        return client.recognizeIdentityCardWithOptions(request, runtime);
    }
}


/**
 * {
 *     "RequestId": "E7659087-512F-5105-A444-FCF810658D76",
 *     "Data": {
 *       "FrontResult": {
 *         "Address": "湖南省城步苗族自治县丹口镇尖口村3组28号",
 *         "FaceRectVertices": [
 *           {
 *             "X": 712,
 *             "Y": 773
 *           },
 *           {
 *             "X": 711,
 *             "Y": 1056
 *           },
 *           {
 *             "X": 387,
 *             "Y": 1073
 *           },
 *           {
 *             "X": 390,
 *             "Y": 771
 *           }
 *         ],
 *         "FaceRectangle": {
 *           "Center": {
 *             "X": 549,
 *             "Y": 923
 *           },
 *           "Angle": 90,
 *           "Size": {
 *             "Height": 302,
 *             "Width": 323
 *           }
 *         },
 *         "CardAreas": [
 *           {
 *             "X": 219,
 *             "Y": 147
 *           },
 *           {
 *             "X": 808,
 *             "Y": 219
 *           },
 *           {
 *             "X": 809,
 *             "Y": 1123
 *           },
 *           {
 *             "X": 210,
 *             "Y": 1166
 *           }
 *         ],
 *         "Gender": "男",
 *         "Nationality": "苗",
 *         "BirthDate": "19920925",
 *         "Name": "瞿贻晓",
 *         "IDNumber": "430529199209255030"
 *       }
 *     }
 *   }
 */