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


import com.aliyun.imageenhan20190930.models.ImageBlindCharacterWatermarkRequest;
import com.aliyun.imageenhan20190930.models.ImageBlindCharacterWatermarkResponse;
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.imageenhan.AImageEncodeBlindCharacterWatermarkRequest;
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/ImageBlindCharacterWatermark
 * 图像隐形文字水印
 * <p>
 * ImageBlindCharacterWatermark
 */
@Component
@Slf4j
@CustomPath("imageEncodeBlindCharacterWatermark")
public class AImageEncodeBlindCharacterWatermarkHandle extends AlibabaBaseHandle<AImageEncodeBlindCharacterWatermarkRequest, ImageBlindCharacterWatermarkResponse> {

    @Autowired
    private com.aliyun.imageenhan20190930.Client client;
    
    @Override
    public String check(AImageEncodeBlindCharacterWatermarkRequest aImageBlindCharacterWatermarkRequest) {
        if (StringUtils.isBlank(aImageBlindCharacterWatermarkRequest.getText())) {
            return "text待加入的水印文字，字数不超过 16 个，超过会影响加水印效果。,text不能为空";
        }
        return checkUrlBase64(aImageBlindCharacterWatermarkRequest);
    }


    @Override
    public ImageBlindCharacterWatermarkResponse run(AImageEncodeBlindCharacterWatermarkRequest aImageBlindCharacterWatermarkRequest, RuntimeOptions runtime) throws Exception {
        ImageBlindCharacterWatermarkRequest imageBlindCharacterWatermarkRequest = new ImageBlindCharacterWatermarkRequest();
        imageBlindCharacterWatermarkRequest.setOriginImageURL(aImageBlindCharacterWatermarkRequest.getImageUrl());
        imageBlindCharacterWatermarkRequest.setFunctionType(aImageBlindCharacterWatermarkRequest.getFunctionType());
        imageBlindCharacterWatermarkRequest.setOutputFileType(aImageBlindCharacterWatermarkRequest.getOutputFileType());
        imageBlindCharacterWatermarkRequest.setQualityFactor(aImageBlindCharacterWatermarkRequest.getQualityFactor());
        imageBlindCharacterWatermarkRequest.setText(aImageBlindCharacterWatermarkRequest.getText());
        return client.imageBlindCharacterWatermarkWithOptions(imageBlindCharacterWatermarkRequest, runtime);
    }
}
