package com.heyu.api.controller.face;


import com.aliyun.facebody20191230.models.FaceTidyupRequest;
import com.aliyun.facebody20191230.models.FaceTidyupResponse;
import com.aliyun.facebody20191230.models.FaceTidyupResponseBody;
import com.heyu.api.alibaba.handle.facebody.AFaceTidyupHandle;
import com.heyu.api.alibaba.request.facebody.AFaceTidyupRequest;
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.FaceTidyupReq;
import com.heyu.api.resp.face.FaceTidyupResp;
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/FaceTidyup
 *述
 * 人脸美型能力可以对人脸的轮廓和五官进行调整。 您也可以通过手动调整美型强度，进一步对人脸进行精细化调整。 关于该接口功能的示例图如下：
 *
 *
 * 应用场景
 * 美颜相机：对拍摄的照片进行大眼、瘦脸、瘦下巴、嘴型、瘦鼻等效果处理，提升人物的社交形象。
 * 相机等 APP：用于相机类 APP 中，提升视觉美感，增加趣味性。
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/face")
@NotIntercept
public class FaceTidyupController extends BaseController {


    @Autowired
    private AFaceTidyupHandle aFaceTidyupHandle;

    /***
     *
     * @param req
     * @return
     */
    @RequestMapping("/tidyup")
    @CacheResult
    public R tidyup(FaceTidyupReq req) {
        FaceTidyupResp faceTidyupResp = new FaceTidyupResp();
        AFaceTidyupRequest faceTidyupRequest = new AFaceTidyupRequest();
        faceTidyupRequest.setImageUrl(req.getImageUrl());
        faceTidyupRequest.setImageBase64(req.getImageBase64());
        faceTidyupRequest.setStrength(req.getStrength());
        faceTidyupRequest.setShapeType(req.getShapeType());
        ApiR<FaceTidyupResponse> aR = aFaceTidyupHandle.handle(faceTidyupRequest);

        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {

            FaceTidyupResponseBody.FaceTidyupResponseBodyData responseBodyData = aR.getData().getBody().getData();
            faceTidyupResp.setImageURL(responseBodyData.getImageURL());
            return R.ok().setData(faceTidyupResp);
        }
        return R.ok();
    }


}
