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


import com.aliyun.imageenhan20190930.models.IntelligentCompositionRequest;
import com.aliyun.imageenhan20190930.models.IntelligentCompositionResponse;
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.AIntelligentCompositionRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * https://next.api.aliyun.com/api/imageenhan/2019-09-30/IntelligentComposition?tab=DOC
 *
 * <p>
 * 智能构图
 * <p>
 * IntelligentComposition
 */
@Component
@Slf4j
@CustomPath("intelligentComposition")
public class AIntelligentCompositionHandle extends AlibabaBaseHandle<AIntelligentCompositionRequest, IntelligentCompositionResponse> {


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

    @Override
    public String check(AIntelligentCompositionRequest aIntelligentCompositionRequest) {
        if (aIntelligentCompositionRequest.getNumBoxes() > 10
                && aIntelligentCompositionRequest.getNumBoxes() < 1) {
            return "numBoxes的取值范围[1,10]";
        }
        return checkUrlBase64(aIntelligentCompositionRequest);
    }

    @Override
    public IntelligentCompositionResponse run(AIntelligentCompositionRequest aIntelligentCompositionRequest, RuntimeOptions runtime) throws Exception {
        IntelligentCompositionRequest intelligentCompositionRequest = new IntelligentCompositionRequest();
        intelligentCompositionRequest.setImageURL(aIntelligentCompositionRequest.getImageUrl());
        intelligentCompositionRequest.setNumBoxes(aIntelligentCompositionRequest.getNumBoxes());
        // 复制代码运行请自行打印 API 的返回值
        return client.intelligentCompositionWithOptions(intelligentCompositionRequest, runtime);
    }
}
