package com.heyu.api.controller.imageenhan;


import com.aliyun.imageenhan20190930.models.MakeSuperResolutionImageResponse;
import com.aliyun.imageenhan20190930.models.MakeSuperResolutionImageResponseBody;
import com.heyu.api.alibaba.handle.imageenhan.AMakeSuperResolutionImageHandle;
import com.heyu.api.alibaba.request.imageenhan.AMakeSuperResolutionImageRequest;
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.AMakeSuperResolutionImageResp;
import com.heyu.api.request.imageenhan.MakeSuperResolutionImageReq;
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/MakeSuperResolutionImage?tab=DOC&lang=JAVA
 *
 *
 * 图像超分
 *
 * MakeSuperResolution|mage
 *
 * 功能描述
 * 图像超分在放大图像分辨率的同时，提升图像细节纹理，降低图像噪声，支持 1-4 倍分辨率放大，支持原分辨率增强，支持多种模式不同效果的输出。 关于该接口功能的示例图如下：
 *
 * 示意图如下所示。
 *
 */
@Slf4j
@RestController
@RequestMapping("/image")
@NotIntercept
public class MakeSuperResolutionImageController extends BaseController {


    @Autowired
    private AMakeSuperResolutionImageHandle amakeSuperResolutionImageHandle;


    @RequestMapping("/makeSuperResolution")
    @CacheResult
    public R superScore(MakeSuperResolutionImageReq req) {

        AMakeSuperResolutionImageResp resp = new AMakeSuperResolutionImageResp();

        AMakeSuperResolutionImageRequest request = new AMakeSuperResolutionImageRequest();

        request.setOutputQuality(req.getOutputQuality());
        request.setUpscaleFactor(req.getUpscaleFactor());
        request.setImageUrl(req.getImageUrl());
        request.setImageBase64(req.getImageBase64());


        ApiR<MakeSuperResolutionImageResponse> aR = amakeSuperResolutionImageHandle.handle(request);
        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            MakeSuperResolutionImageResponseBody.MakeSuperResolutionImageResponseBodyData responseBodyData = aR.getData().getBody().getData();
            resp.setImageURL(responseBodyData.getUrl());
            return R.ok().setData(resp);

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

}
