package com.heyu.api.controller.imageenhan;


import com.aliyun.imageenhan20190930.models.RemoveImageSubtitlesResponse;
import com.aliyun.imageenhan20190930.models.RemoveImageSubtitlesResponseBody;
import com.heyu.api.alibaba.handle.imageenhan.ARemoveImageSubtitlesHandle;
import com.heyu.api.alibaba.request.imageenhan.ARemoveImageSubtitlesRequest;
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.RemoveImageSubtitlesReq;
import com.heyu.api.resp.imageenhan.RemoveImageSubtitlesResp;
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/RemoveImageSubtitles?tab=DOC&lang=JAVA&RegionId=cn-shanghai
 *
 *字幕擦除
 *
 * RemovelmageSubtitles
 *
 *
 * 功能描述
 * 字幕擦除能力可以擦除图片中的标准字幕。
 *
 */
@Slf4j
@RestController
@RequestMapping("/image")
@NotIntercept
public class RemoveImageSubtitlesController extends BaseController {

    @Autowired
    private ARemoveImageSubtitlesHandle removeImageSubtitlesHandle;

    @RequestMapping("/removeSubtitles")
    @CacheResult
    public R removeSubtitles(RemoveImageSubtitlesReq req) {
        RemoveImageSubtitlesResp resp = new RemoveImageSubtitlesResp();

        ARemoveImageSubtitlesRequest request = new ARemoveImageSubtitlesRequest();
        request.setImageUrl(req.getImageUrl());
        request.setImageBase64(req.getImageBase64());
        request.setX(req.getX());
        request.setY(req.getY());
        request.setW(req.getW());
        request.setH(req.getH());
        ApiR<RemoveImageSubtitlesResponse> aR = removeImageSubtitlesHandle.handle(request);

        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            RemoveImageSubtitlesResponseBody.RemoveImageSubtitlesResponseBodyData responseBodyData = aR.getData().getBody().getData();
            resp.setImageURL(responseBodyData.getImageURL());
            return R.ok().setData(resp);

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