package com.heyu.api.controller.face;


import com.aliyun.facebody20191230.models.EnhanceFaceResponse;
import com.aliyun.facebody20191230.models.EnhanceFaceResponseBody;
import com.heyu.api.alibaba.handle.facebody.AEnhanceFaceHandle;
import com.heyu.api.alibaba.request.facebody.AEnhanceFaceRequest;
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.EnhanceFaceReq;
import com.heyu.api.resp.face.EnhanceFaceResp;
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/EnhanceFace?RegionId=cn-shanghai
 *
 *人脸修复增强
 *
 * EnhanceFace
 *
 * 功能描述
 * 人脸修复增强能力可以对输入图像中的人脸进行裁剪、对齐、细节增强，最后再融合回原图。 关于该接口功能的示例图如下：
 *
 * 拍摄素材增强：对拍摄时因曝光不足、对焦不准、手抖模糊的照片，通过人脸修复增强技术，可以弥补拍摄时的不足，对照片进行修复。
 * 老照片修复：对早期拍摄的分辨率低或不清晰的人像照片，进行修复增强，可以在保留老照片质感的同时提升人像清晰度。
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/face")
@NotIntercept
public class EnhanceFaceController extends BaseController {


    @Autowired
    private AEnhanceFaceHandle aEnhanceFaceHandle;


    @RequestMapping("/enhance")
    @CacheResult
    public R count(EnhanceFaceReq req) {
        EnhanceFaceResp resp = new EnhanceFaceResp();
        AEnhanceFaceRequest request = new AEnhanceFaceRequest();
        request.setImageBase64(req.getImageBase64());
        request.setImageUrl(req.getImageUrl());
        ApiR<EnhanceFaceResponse> aR = aEnhanceFaceHandle.handle(request);
        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            EnhanceFaceResponseBody.EnhanceFaceResponseBodyData responseBodyData = aR.getData().getBody().getData();
            resp.setImageURL(responseBodyData.getImageURL());
            return R.ok().setData(resp);
        }
        return R.ok();
    }




}
