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


import com.alibaba.fastjson.JSON;
import com.aliyun.imageseg20191230.models.SegmentCommonImageRequest;
import com.aliyun.imageseg20191230.models.SegmentCommonImageResponse;
import com.aliyun.teautil.models.RuntimeOptions;
import com.heyu.api.data.annotation.CustomPath;
import com.heyu.api.data.constants.ApiConstants;
import com.heyu.api.alibaba.AlibabaBaseHandle;
import com.heyu.api.alibaba.request.imageseg.ASegmentCommonImageRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * https://next.api.aliyun.com/api/imageseg/2019-12-30/SegmentCommonImage?tab=DOC
 * <p>
 * <p>
 * 通用分割
 * <p>
 * SegmentCommonImage
 */
@Component
@Slf4j
@CustomPath("segmentCommonImage")
public class ASegmentCommonImageHandle extends AlibabaBaseHandle<ASegmentCommonImageRequest, SegmentCommonImageResponse> {

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


    @Override
    public String check(ASegmentCommonImageRequest aSegmentCommonImageRequest) {
        if (!ApiConstants.suportMaskReturnType.contains(aSegmentCommonImageRequest.getReturnType())) {
            return "returnType仅支持" + JSON.toJSONString(aSegmentCommonImageRequest.getReturnType());
        }
        return checkUrlBase64(aSegmentCommonImageRequest);
    }


    @Override
    public SegmentCommonImageResponse run(ASegmentCommonImageRequest aSegmentCommonImageRequest, RuntimeOptions runtime) throws Exception {
        SegmentCommonImageRequest segmentCommonImageRequest = new SegmentCommonImageRequest();
        segmentCommonImageRequest.setImageURL(aSegmentCommonImageRequest.getImageUrl());
        segmentCommonImageRequest.setReturnForm(aSegmentCommonImageRequest.getReturnType());
        // 复制代码运行请自行打印 API 的返回值
        return client.segmentCommonImageWithOptions(segmentCommonImageRequest, runtime);
    }
}
