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


import com.alibaba.fastjson.JSON;
import com.aliyun.facebody20191230.models.GenerateHumanSketchStyleRequest;
import com.aliyun.facebody20191230.models.GenerateHumanSketchStyleResponse;
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.facebody.AGenerateHumanSketchStyleRequest;
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/facebody/2019-12-30/GenerateHumanSketchStyle?tab=DEMO&lang=JAVA
 * 人像素描风格化
 */
@Component
@Slf4j
@CustomPath("generateHumanSketchStyle")
public class AGenerateHumanSketchStyleHandle extends AlibabaBaseHandle<AGenerateHumanSketchStyleRequest, GenerateHumanSketchStyleResponse> {

    public final static List<String> suportType = Arrays.asList("head", "full");

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


    @Override
    public String check(AGenerateHumanSketchStyleRequest aGenerateHumanSketchStyleRequest) {
        if (!suportType.contains(aGenerateHumanSketchStyleRequest.getReturnType())) {
            return "returnType请传" + JSON.toJSONString(aGenerateHumanSketchStyleRequest.getReturnType());
        }
        return checkUrlBase64(aGenerateHumanSketchStyleRequest);
    }


    @Override
    public GenerateHumanSketchStyleResponse run(AGenerateHumanSketchStyleRequest aGenerateHumanSketchStyleRequest, RuntimeOptions runtime) throws Exception {
        GenerateHumanSketchStyleRequest generateHumanSketchStyleRequest = new GenerateHumanSketchStyleRequest();
        generateHumanSketchStyleRequest.setImageURL(aGenerateHumanSketchStyleRequest.getImageUrl());
        generateHumanSketchStyleRequest.setReturnType(aGenerateHumanSketchStyleRequest.getReturnType());
        // 复制代码运行请自行打印 API 的返回值
        return client.generateHumanSketchStyleWithOptions(generateHumanSketchStyleRequest, runtime);
    }
}
