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


import com.aliyun.imageseg20191230.models.SegmentBodyRequest;
import com.aliyun.imageseg20191230.models.SegmentBodyResponse;
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.imageseg.ASegmentBodyRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * https://next.api.aliyun.com/api/imageseg/2019-12-30/SegmentBody?tab=DOC
 * <p>
 * <p>
 * 人体分割
 * <p>
 * SegmentBody
 */

@Component
@Slf4j
@CustomPath("segmentBody")
public class ASegmentBodyHandle extends AlibabaBaseHandle<ASegmentBodyRequest, SegmentBodyResponse> {

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

    public final List<String> suport = Arrays.asList("mask", "crop", "whiteBK");

    @Override
    public String check(ASegmentBodyRequest aSegmentBodyRequest) {
        if (!suport.contains(aSegmentBodyRequest.getReturnType())) {
            return "returnType只能是mask，crop，whiteBK";
        }
        return checkUrlBase64(aSegmentBodyRequest);
    }


    @Override
    public SegmentBodyResponse run(ASegmentBodyRequest aSegmentBodyRequest, RuntimeOptions runtime) throws Exception {
        SegmentBodyRequest segmentBodyRequest = new SegmentBodyRequest();
        segmentBodyRequest.setImageURL(aSegmentBodyRequest.getImageUrl());
        segmentBodyRequest.setReturnForm(aSegmentBodyRequest.getReturnType());
        // 复制代码运行请自行打印 API 的返回值
        return client.segmentBodyWithOptions(segmentBodyRequest, runtime);
    }
}
