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

import com.aliyun.ocr20191230.models.RecognizePdfRequest;
import com.aliyun.ocr20191230.models.RecognizePdfResponse;
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.ARecognizePdfRequest;
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/RecognizeTicketInvoice
 * PDF识别
 */
@Component
@Slf4j
@CustomPath("pdf")
public class ARecognizePdfHandle extends AlibabaBaseHandle<ARecognizePdfRequest, RecognizePdfResponse> {


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


    @Override
    public String check(ARecognizePdfRequest aRecognizePdfRequest) {
        return checkUrlBase64(aRecognizePdfRequest);
    }


    @Override
    public RecognizePdfResponse run(ARecognizePdfRequest aRecognizePdfRequest, RuntimeOptions runtime) throws Exception {


        RecognizePdfRequest request = new RecognizePdfRequest();
        request.setFileURL(aRecognizePdfRequest.getImageUrl());
        // 复制代码运行请自行打印 API 的返回值
        return client.recognizePdfWithOptions(request, runtime);
    }
}
