package com.heyu.api.controller.face;


import com.aliyun.facebody20191230.models.FaceBeautyRequest;
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.baidu.response.certificate.BSocialSecurityCardResp;
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.DetectCelebrityReq;
import com.heyu.api.request.face.FaceBeautyReq;
import com.heyu.api.resp.face.FaceBeautyResp;
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/LiquifyFace
 *
 *智能瘦脸 LiquifyFace
 *
 * 功能描述
 * 智能瘦脸功能可实现输入一张人物图像，输出脸部五官调整瘦脸后的图像。 关于该接口功能的示例图如下：
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/face")
@NotIntercept
public class FaceBeautyController extends BaseController {


    @Autowired
    private AFaceBeautyHandle afaceBeautyHandle;

    @RequestMapping("/beauty")
    @CacheResult
    public R beauty(FaceBeautyReq req) {
        FaceBeautyResp resp = new FaceBeautyResp();

        AFaceBeautyRequest aFaceBeautyRequest = new AFaceBeautyRequest();
        aFaceBeautyRequest.setImageBase64(req.getImageBase64());
        aFaceBeautyRequest.setImageUrl(req.getImageUrl());
        aFaceBeautyRequest.setWhite(req.getWhite());
        aFaceBeautyRequest.setSharp(req.getSharp());
        aFaceBeautyRequest.setSmooth(req.getSmooth());

        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());
    }
}
