package com.heyu.api.controller.imageenhan;


import com.aliyun.imageenhan20190930.models.AssessExposureResponse;
import com.aliyun.imageenhan20190930.models.AssessExposureResponseBody;
import com.heyu.api.alibaba.handle.imageenhan.AAssessExposureHandle;
import com.heyu.api.alibaba.request.imageenhan.AAssessExposureRequest;
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/AssessExposure?tab=DOC
 *
 * 功能描述
 * 图像曝光度评分能力可以对输入的图像进行曝光度评分，评分越高，曝光越大。
 */
@Slf4j
@RestController
@RequestMapping("/image")
@NotIntercept
public class AssessExposureController extends BaseController {


    @Autowired
    private AAssessExposureHandle aAssessExposureHandle;


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


        AAssessExposureRequest assessExposureRequest = new AAssessExposureRequest();
        assessExposureRequest.setImageBase64(req.getImageBase64());
        assessExposureRequest.setImageUrl(req.getImageUrl());

        ApiR<AssessExposureResponse> aR = aAssessExposureHandle.handle(assessExposureRequest);
        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            AssessExposureResponseBody.AssessExposureResponseBodyData responseBodyData = aR.getData().getBody().getData();

            resp.setExposure(responseBodyData.getExposure());
            return R.ok().setData(resp);

        }
        return R.ok();
    }
}
