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

import com.aliyun.ocr20191230.models.RecognizeDrivingLicenseRequest;
import com.aliyun.ocr20191230.models.RecognizeDrivingLicenseResponse;
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.common.text.ARecognizeDrivingLicenseRequest;
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/RecognizeDrivingLicense?tab=DOC
 * 行驶证识别
 */
@Component
@Slf4j
@CustomPath("drivingLicense")
public class ARecognizeDrivingLicenseHandle extends AlibabaBaseHandle<ARecognizeDrivingLicenseRequest, RecognizeDrivingLicenseResponse> {
    @Autowired
    private com.aliyun.ocr20191230.Client client;

    @Override
    public String check(ARecognizeDrivingLicenseRequest aRecognizeDriverLicenseRequest) {
        String check = checkUrlBase64(aRecognizeDriverLicenseRequest);
        if (check != null) {
            return check;
        }
        if (StringUtils.isBlank(aRecognizeDriverLicenseRequest.getSide())) {
            return "请上传site字段，face：表示首页，back：表示副页";
        }
        return null;
    }


    @Override
    public RecognizeDrivingLicenseResponse run(ARecognizeDrivingLicenseRequest recognizeDrivingLicenseRequest, RuntimeOptions runtime) throws Exception {
        RecognizeDrivingLicenseRequest request = new RecognizeDrivingLicenseRequest();
        request.setSide(recognizeDrivingLicenseRequest.getSide());

        // 复制代码运行请自行打印 API 的返回值
        return client.recognizeDrivingLicenseWithOptions(request, runtime);
    }


}