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

import com.aliyun.facebody20191230.models.RetouchSkinRequest;
import com.aliyun.facebody20191230.models.RetouchSkinResponse;
import com.aliyun.teautil.models.RuntimeOptions;
import com.heyu.api.data.annotation.CustomPath;
import com.heyu.api.data.utils.StringUtils;
import com.heyu.api.alibaba.AlibabaBaseHandle;
import com.heyu.api.alibaba.request.facebody.ARetouchSkinRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * https://next.api.aliyun.com/api/facebody/2019-12-30/RetouchSkin?tab=DEMO&lang=JAVA
 * <p>
 * 智能美肤
 *
 * RetouchSkin
 */
@Component
@Slf4j
@CustomPath("retouchSkin")
public class ARetouchSkinHandle extends AlibabaBaseHandle<ARetouchSkinRequest, RetouchSkinResponse> {

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


    @Override
    public String check(ARetouchSkinRequest aRetouchSkinRequest) {
        String check = checkUrlBase64(aRetouchSkinRequest);
        if (StringUtils.isNotBlank(check)) {
            return check;
        }
        if (aRetouchSkinRequest.getRetouchDegree() < 0 || aRetouchSkinRequest.getRetouchDegree() > 1.5) {
            return "retouchDegree的范围在[0,1.5]";
        }

        if (aRetouchSkinRequest.getWhiteningDegree() < 0 || aRetouchSkinRequest.getWhiteningDegree() > 1.5) {
            return "whiteningDegree的范围在[0,1.5]";
        }
        return null;
    }


    @Override
    public RetouchSkinResponse run(ARetouchSkinRequest aRetouchSkinRequest, RuntimeOptions runtime) throws Exception {
        RetouchSkinRequest request = new RetouchSkinRequest();
        request.setImageURL(aRetouchSkinRequest.getImageUrl());
        request.setRetouchDegree(aRetouchSkinRequest.getRetouchDegree());
        request.setWhiteningDegree(aRetouchSkinRequest.getWhiteningDegree());

        // 复制代码运行请自行打印 API 的返回值
        return client.retouchSkinWithOptions(request, runtime);
    }
}
