package com.heyu.api.controller.imageenhan;


import com.aliyun.imageenhan20190930.models.AssessCompositionResponse;
import com.aliyun.imageenhan20190930.models.AssessCompositionResponseBody;
import com.heyu.api.alibaba.handle.imageenhan.AAssessCompositionHandle;
import com.heyu.api.alibaba.request.imageenhan.AAssessCompositionRequest;
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.ImageBlindPicWatermarkReq;
import com.heyu.api.resp.imageenhan.ImageDecodeBlindPicWatermarkResp;
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/AssessComposition?tab=DEMO&lang=JAVA&RegionId=cn-shanghai
 *
 * 图像构图美学评分 AssessComposition
 *功能描述
 * 图像构图美学评分能力可以对输入的图像进行构图美学评分，评分越高，构图效果越好。
 *
 */
@Slf4j
@RestController
@RequestMapping("/image")
@NotIntercept
public class AssessCompositionController extends BaseController {

    @Autowired
    private AAssessCompositionHandle assessCompositionHandle;


    @RequestMapping("/composition")
    @CacheResult
    public R composition(ImageBlindPicWatermarkReq req) {
        ImageDecodeBlindPicWatermarkResp resp = new ImageDecodeBlindPicWatermarkResp();

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


        ApiR<AssessCompositionResponse> apiR = assessCompositionHandle.handle(request);
        if (apiR.isSuccess() && isSuccessStatusCode(apiR.getData().getStatusCode())) {
            AssessCompositionResponseBody.AssessCompositionResponseBodyData responseBodyData = apiR.getData().getBody().getData();
            resp.setScore(responseBodyData.getScore());

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

        }


        return R.error();
    }


}
