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

import com.alibaba.fastjson.JSON;
import com.aliyun.imageseg20191230.models.SegmentCommodityRequest;
import com.aliyun.imageseg20191230.models.SegmentCommodityResponse;
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.ASegmentCommodityRequest;
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/SegmentCommodity
 * <p>
 * <p>
 * 商品分割
 * <p>
 * SegmentCommodity
 */

@Component
@Slf4j
@CustomPath("segmentCommodity")
public class ASegmentCommodityHandle extends AlibabaBaseHandle<ASegmentCommodityRequest, SegmentCommodityResponse> {

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





    @Override
    public String check(ASegmentCommodityRequest aSegmentCommodityRequest) {
        if (!ApiConstants.suportMaskReturnType.contains(aSegmentCommodityRequest.getReturnType())) {
            return "returnType请输入" + JSON.toJSONString(ApiConstants.suportMaskReturnType);
        }
        return checkUrlBase64(aSegmentCommodityRequest);
    }

    @Override
    public SegmentCommodityResponse run(ASegmentCommodityRequest aSegmentCommodityRequest, RuntimeOptions runtime) throws Exception {
        SegmentCommodityRequest commodityRequest = new SegmentCommodityRequest();
        commodityRequest.setImageURL(aSegmentCommodityRequest.getImageUrl());
        commodityRequest.setReturnForm(aSegmentCommodityRequest.getReturnType());
        // 复制代码运行请自行打印 API 的返回值
        return client.segmentCommodityWithOptions(commodityRequest, runtime);
    }
}
