package com.heyu.api.controller.face;


import com.aliyun.facebody20191230.models.FaceMakeupResponse;
import com.aliyun.facebody20191230.models.FaceMakeupResponseBody;
import com.heyu.api.alibaba.handle.facebody.AFaceMakeupHandle;
import com.heyu.api.alibaba.request.facebody.ADetectInfraredLivingFaceRequest;
import com.heyu.api.alibaba.request.facebody.AFaceMakeupRequest;
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.FaceMakeupReq;
import com.heyu.api.resp.face.FaceMakeupResp;
import lombok.Data;
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/FaceMakeup?RegionId=cn-shanghai
 人脸美妆

 FaceMakeup
 *
 *
 * 应用场景
 * 在线试妆：可用于在线试妆等虚拟试妆场景，用户可体验接近本人真实情况的上妆效果，降低商家的运营成本。
 * 美颜修图：可用于手机自拍修图等人像美化场景，一键实现美妆效果，帮助用户快速打造精致五官，提升个人社交形象。
 * 相机等 APP：用于相机类 APP 中，提升视觉美感，增加趣味性。
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/face")
@NotIntercept
public class FaceMakeupController extends BaseController {


    @Autowired
    private AFaceMakeupHandle aFaceMakeupHandle;


    @RequestMapping("/makeup")
    @CacheResult
    public R makeup(FaceMakeupReq req) {
        FaceMakeupResp faceMakeupResp = new FaceMakeupResp();
        AFaceMakeupRequest request = new AFaceMakeupRequest();

        request.setImageBase64(req.getImageBase64());
        request.setImageUrl(req.getImageUrl());
        request.setMakeupType(req.getMakeupType());
        request.setStrength(req.getStrength());
        request.setResourceType(req.getResourceType());

        ApiR<FaceMakeupResponse> aR = aFaceMakeupHandle.handle(request);
        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            FaceMakeupResponseBody.FaceMakeupResponseBodyData responseBodyData = aR.getData().getBody().getData();
            faceMakeupResp.setImageURL(responseBodyData.getImageURL());
            return R.ok().setData(faceMakeupResp);
        }
        return R.ok();
    }


}
