package com.heyu.api.controller.imageenhan;


import com.aliyun.imageenhan20190930.models.AssessSharpnessResponse;
import com.aliyun.imageenhan20190930.models.AssessSharpnessResponseBody;
import com.heyu.api.alibaba.handle.imageenhan.AAssessSharpnessHandle;
import com.heyu.api.alibaba.request.imageenhan.AAssessSharpnessRequest;
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.AssessExposureReq;
import com.heyu.api.resp.imageenhan.AssessExposureResp;
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/AssessSharpness
 *图像清晰度评分 AssessSharpness
 *功能描述
 * 图像清晰度评分能力可以对输入的图像进行清晰度评分，评分越高图像越清晰。
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/assess")
@NotIntercept
public class AssessSharpnessController extends BaseController {


    @Autowired
    private AAssessSharpnessHandle aAssessSharpnessHandle;


    @RequestMapping("/sharpness")
    @CacheResult
    public R exposure(AssessExposureReq req) {
        AssessExposureResp resp = new AssessExposureResp();

        AAssessSharpnessRequest request = new AAssessSharpnessRequest();
        request.setImageUrl(req.getImageUrl());
        request.setImageBase64(req.getImageBase64());

        ApiR<AssessSharpnessResponse> aR = aAssessSharpnessHandle.handle(request);
        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            AssessSharpnessResponseBody.AssessSharpnessResponseBodyData responseBodyData = aR.getData().getBody().getData();

            resp.setExposure(responseBodyData.getSharpness());

            return R.ok().setData(resp);

        }

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