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


import com.alibaba.fastjson.JSON;
import com.aliyun.imageseg20191230.models.SegmentFoodRequest;
import com.aliyun.imageseg20191230.models.SegmentFoodResponse;
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.ASegmentFoodRequest;
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/ParseFace?tab=DEMO&lang=JAVA
 * <p>
 * <p>
 * 食品分割
 * <p>
 * SegmentFood
 */
@Component
@Slf4j
@CustomPath("aSegmentFood")
public class ASegmentFoodHandle extends AlibabaBaseHandle<ASegmentFoodRequest, SegmentFoodResponse> {


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


    @Override
    public String check(ASegmentFoodRequest aSegmentFoodRequest) {
        if (!ApiConstants.suportMaskReturnType.contains(aSegmentFoodRequest.getReturnType())) {
            return "returnType只能接收" + JSON.toJSONString(ApiConstants.suportMaskReturnType);
        }
        return checkUrlBase64(aSegmentFoodRequest);
    }


    @Override
    public SegmentFoodResponse run(ASegmentFoodRequest aSegmentFoodRequest, RuntimeOptions runtime) throws Exception {
        SegmentFoodRequest segmentFoodRequest = new SegmentFoodRequest();
        segmentFoodRequest.setImageURL(aSegmentFoodRequest.getImageUrl());
        segmentFoodRequest.setReturnForm(aSegmentFoodRequest.getReturnType());
        // 复制代码运行请自行打印 API 的返回值
        return client.segmentFoodWithOptions(segmentFoodRequest, runtime);
    }

}
