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


import com.aliyun.imageseg20191230.models.SegmentClothRequest;
import com.aliyun.imageseg20191230.models.SegmentClothResponse;
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.ASegmentClothRequest;
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/SegmentCloth?tab=DOC&lang=JAVA
 * <p>
 * <p>
 * 服饰分割
 * <p>
 * SegmentCloth
 */
@Component
@Slf4j
@CustomPath("segmentCloth")
public class ASegmentClothHandle extends AlibabaBaseHandle<ASegmentClothRequest, SegmentClothResponse> {

    @Autowired
    private com.aliyun.imageseg20191230.Client client;
    public static final List<String> clothClass = Arrays.asList("tops","coat","skirt","pants","bag","shoes","hat");

    @Override
    public String check(ASegmentClothRequest aSegmentClothRequest) {
        if (aSegmentClothRequest.getOutMode() != 0
                && aSegmentClothRequest.getOutMode() != 1) {
            return "outMode的取值范围为0,1";
        }

        if(!clothClass.contains(aSegmentClothRequest.getClothClass())){
            return "clothClass的取值范围" + aSegmentClothRequest.getClothClass();
        }
        return checkUrlBase64(aSegmentClothRequest);
    }

    @Override
    public SegmentClothResponse run(ASegmentClothRequest aSegmentClothRequest, RuntimeOptions runtime) throws Exception {
        SegmentClothRequest segmentClothRequest = new SegmentClothRequest();
        segmentClothRequest.setClothClass(aSegmentClothRequest.getClothClass());
        segmentClothRequest.setImageURL(aSegmentClothRequest.getImageUrl());
        segmentClothRequest.setOutMode(aSegmentClothRequest.getOutMode());
        segmentClothRequest.setReturnForm(aSegmentClothRequest.getReturnType());
        // 复制代码运行请自行打印 API 的返回值
        return client.segmentClothWithOptions(segmentClothRequest, runtime);
    }

}
