package com.heyu.api.controller.face;


import com.aliyun.facebody20191230.models.FaceBeautyResponse;
import com.aliyun.facebody20191230.models.FaceBeautyResponseBody;
import com.heyu.api.alibaba.handle.facebody.AFaceBeautyHandle;
import com.heyu.api.alibaba.request.facebody.AFaceBeautyRequest;
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.face.FaceBeauty4Req;
import com.heyu.api.resp.face.FaceBeauty4Resp;
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/facebody/2019-12-30/FaceBeauty?RegionId=cn-shanghai
 *
 *人脸美颜
 *
 *
 *
 FaceBeauty

 功能描述
 人脸美颜能力可以对图像中的人脸进行美颜。产品支持以下功能：

 人脸美颜：磨皮、美白、锐化（清晰度）、平滑度等。
 参数调整：可自定义调整参数，提升个人形象

 */
@Slf4j
@RestController
@RequestMapping("/face")
@NotIntercept
public class FaceBeauty4Controller extends BaseController {


    @Autowired
    private AFaceBeautyHandle aFaceBeautyHandle;


    @RequestMapping("/beauty4")
    @CacheResult
    public R beauty4(FaceBeauty4Req req) {
        FaceBeauty4Resp resp = new FaceBeauty4Resp();

        AFaceBeautyRequest aFaceBeautyRequest = new AFaceBeautyRequest();
        aFaceBeautyRequest.setSmooth(req.getSmooth());
        aFaceBeautyRequest.setWhite(req.getWhite());
        aFaceBeautyRequest.setImageUrl(req.getImageUrl());
        aFaceBeautyRequest.setImageBase64(req.getImageBase64());
        aFaceBeautyRequest.setSharp(req.getSharp());
        ApiR<FaceBeautyResponse> aR = aFaceBeautyHandle.handle(aFaceBeautyRequest);
        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            FaceBeautyResponseBody.FaceBeautyResponseBodyData responseBodyData = aR.getData().getBody().getData();
            resp.setImageURL(responseBodyData.getImageURL());
            return R.ok().setData(resp);

        }

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