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

import com.aliyun.ocr20191230.models.RecognizeQrCodeRequest;
import com.aliyun.ocr20191230.models.RecognizeQrCodeResponse;
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.ARecognizeQrCodeRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

/**
 * https://next.api.aliyun.com/api/ocr/2019-12-30/RecognizeTable
 * 二维码识别
 */
@Component
@Slf4j
@CustomPath("qrCode")
public class ARecognizeQrCodeHandle extends AlibabaBaseHandle<ARecognizeQrCodeRequest, RecognizeQrCodeResponse> {
    @Autowired
    private com.aliyun.ocr20191230.Client client;

    @Override
    public String check(ARecognizeQrCodeRequest aRecognizeQrCodeRequest) {
        return checkUrlBase64(aRecognizeQrCodeRequest);
    }


    @Override
    public RecognizeQrCodeResponse run(ARecognizeQrCodeRequest aRecognizeQrCodeRequest, RuntimeOptions runtime) throws Exception {


        RecognizeQrCodeRequest request = new RecognizeQrCodeRequest();
        java.util.List<RecognizeQrCodeRequest.RecognizeQrCodeRequestTasks> tasks = new ArrayList<>();
        RecognizeQrCodeRequest.RecognizeQrCodeRequestTasks task = new RecognizeQrCodeRequest.RecognizeQrCodeRequestTasks();
        task.setImageURL(aRecognizeQrCodeRequest.getImageUrl());
        tasks.add(task);

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

}
