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


import com.aliyun.objectdet20191230.models.DetectObjectRequest;
import com.aliyun.objectdet20191230.models.DetectObjectResponse;
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.objectdet.ADetectObjectRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * https://next.api.aliyun.com/api/objectdet/2019-12-30/DetectMainBody?tab=DEMO&lang=JAVA
 * <p>
 * 物体检测
 * <p>
 * DetectObject
 */

@Component
@Slf4j
@CustomPath("detectObject")
public class ADetectObjectHandle extends AlibabaBaseHandle<ADetectObjectRequest, DetectObjectResponse> {

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

    @Override
    public String check(ADetectObjectRequest aDetectObjectRequest) {
        return checkUrlBase64(aDetectObjectRequest);
    }

    @Override
    public DetectObjectResponse run(ADetectObjectRequest aDetectObjectRequest, RuntimeOptions runtime) throws Exception {
        DetectObjectRequest detectObjectRequest = new DetectObjectRequest();
        detectObjectRequest.setImageURL(aDetectObjectRequest.getImageUrl());
        // 复制代码运行请自行打印 API 的返回值
        return client.detectObjectWithOptions(detectObjectRequest, runtime);
    }
}
