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


import com.aliyun.imageenhan20190930.models.GenerateCartoonizedImageRequest;
import com.aliyun.imageenhan20190930.models.GenerateCartoonizedImageResponse;
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.imageenhan.AGenerateCartoonizedImageRequest;
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/imageenhan/2019-09-30/GenerateCartoonizedImage?tab=DOC&lang=JAVA
 * 生成式图像卡通化
 * <p>
 * GenerateCartoonized mage
 */
@Component
@Slf4j
@CustomPath("generateCartoonizedImage")
public class AGenerateCartoonizedImageHandle extends AlibabaBaseHandle<AGenerateCartoonizedImageRequest, GenerateCartoonizedImageResponse> {

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


    public List<Integer> suportType = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8);

    @Override
    public String check(AGenerateCartoonizedImageRequest aGenerateCartoonizedImageRequest) {
        if (!suportType.contains(aGenerateCartoonizedImageRequest.getCartoonizedType())) {
            return "cartoonizedType的取值范围[0,1,2,3,4,5,6,7,8]";
        }
        return checkUrlBase64(aGenerateCartoonizedImageRequest);
    }


    @Override
    public GenerateCartoonizedImageResponse run(AGenerateCartoonizedImageRequest aGenerateCartoonizedImageRequest, RuntimeOptions runtime) throws Exception {
        GenerateCartoonizedImageRequest generateCartoonizedImageRequest = new GenerateCartoonizedImageRequest();
        generateCartoonizedImageRequest.setImageUrl(aGenerateCartoonizedImageRequest.getImageUrl());
        generateCartoonizedImageRequest.setIndex(aGenerateCartoonizedImageRequest.getCartoonizedType() + "");
        // 复制代码运行请自行打印 API 的返回值
        return client.generateCartoonizedImageWithOptions(generateCartoonizedImageRequest, runtime);
    }
}
