package com.heyu.api.controller.imageenhan;


import com.aliyun.imageenhan20190930.models.RemoveImageWatermarkResponse;
import com.aliyun.imageenhan20190930.models.RemoveImageWatermarkResponseBody;
import com.heyu.api.alibaba.handle.imageenhan.ARemoveImageWatermarkHandle;
import com.heyu.api.alibaba.request.imageenhan.ARemoveImageWatermarkRequest;
import com.heyu.api.controller.BaseController;
import com.heyu.api.data.annotation.CacheResult;
import com.heyu.api.data.annotation.NotIntercept;
import com.heyu.api.data.utils.ApiR;
import com.heyu.api.data.utils.R;
import com.heyu.api.request.imageenhan.RemoveImageWatermarkReq;
import com.heyu.api.resp.imageenhan.RemoveImageWatermarkResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/***
 *https://next.api.aliyun.com/api/imageenhan/2019-09-30/RemoveImageWatermark?tab=DEMO&lang=JAVA&RegionId=cn-shanghai
 *
 *台标标志擦除
 *
 * RemovelmageWatermark
 *
 *
 * 功能描述
 * 图像标志擦除能力用于擦除图片中的常见标志，如台标、互联网平台 Logo 标志等。
 *
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/image")
@NotIntercept
public class RemoveImageWatermarkController extends BaseController {

    @Autowired
    private ARemoveImageWatermarkHandle removeImageWatermarkHandle;


    @RequestMapping("/removeWatermark")
    @CacheResult
    public R removeWatermark(RemoveImageWatermarkReq req) {
        RemoveImageWatermarkResp resp = new RemoveImageWatermarkResp();

        ARemoveImageWatermarkRequest removeImageWatermarkRequest = new ARemoveImageWatermarkRequest();
        removeImageWatermarkRequest.setImageBase64(req.getImageBase64());
        removeImageWatermarkRequest.setImageUrl(req.getImageUrl());

        ApiR<RemoveImageWatermarkResponse> aR = removeImageWatermarkHandle.handle(removeImageWatermarkRequest);
        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            RemoveImageWatermarkResponseBody.RemoveImageWatermarkResponseBodyData responseBodyData = aR.getData().getBody().getData();
            resp.setImageURL(responseBodyData.getImageURL());
            return R.ok().setData(resp);

        }
        return R.ok(aR.getErrorMsg());
    }

}
