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


import com.aliyun.imageenhan20190930.models.RemoveImageSubtitlesRequest;
import com.aliyun.imageenhan20190930.models.RemoveImageSubtitlesResponse;
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.ARemoveImageSubtitlesRequest;
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/RemoveImageSubtitles?tab=DEMO&lang=JAVA
 * <p>
 * 字幕擦除
 * <p>
 * RemovelmageSubtitles
 */
@Component
@Slf4j
@CustomPath("removeImageSubtitles")
public class ARemoveImageSubtitlesHandle extends AlibabaBaseHandle<ARemoveImageSubtitlesRequest, RemoveImageSubtitlesResponse> {

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


    @Override
    public String check(ARemoveImageSubtitlesRequest aRemoveImageSubtitlesRequest) {
        if (aRemoveImageSubtitlesRequest.getX() == null
                || aRemoveImageSubtitlesRequest.getY() == null
                || aRemoveImageSubtitlesRequest.getW() == null
                || aRemoveImageSubtitlesRequest.getH() == null) {
            return "x,y,w,h不能为空";
        }

        if (aRemoveImageSubtitlesRequest.getX() > 1 || aRemoveImageSubtitlesRequest.getX() < 0) {
            return "x的取值范围 0 ~1";
        }
        if (aRemoveImageSubtitlesRequest.getY() > 1 || aRemoveImageSubtitlesRequest.getY() < 0) {
            return "y的取值范围 0 ~1";
        }

        if (aRemoveImageSubtitlesRequest.getW() > 1 || aRemoveImageSubtitlesRequest.getW() < 0) {
            return "w的取值范围 0 ~1";
        }

        if (aRemoveImageSubtitlesRequest.getH() > 1 || aRemoveImageSubtitlesRequest.getH() < 0) {
            return "h的取值范围 0 ~1";
        }
        return checkUrlBase64(aRemoveImageSubtitlesRequest);
    }



    @Override
    public RemoveImageSubtitlesResponse run(ARemoveImageSubtitlesRequest aRemoveImageSubtitlesRequest, RuntimeOptions runtime) throws Exception {
        RemoveImageSubtitlesRequest removeImageSubtitlesRequest = new RemoveImageSubtitlesRequest();
        removeImageSubtitlesRequest.setImageURL(aRemoveImageSubtitlesRequest.getImageUrl());
        removeImageSubtitlesRequest.setBX(aRemoveImageSubtitlesRequest.getX());
        removeImageSubtitlesRequest.setBY(aRemoveImageSubtitlesRequest.getY());
        removeImageSubtitlesRequest.setBH(aRemoveImageSubtitlesRequest.getH());
        removeImageSubtitlesRequest.setBW(aRemoveImageSubtitlesRequest.getW());
        // 复制代码运行请自行打印 API 的返回值
        return client.removeImageSubtitlesWithOptions(removeImageSubtitlesRequest, runtime);
    }
}
