package com.heyu.api.controller.face;


import com.aliyun.facebody20191230.models.BlurFaceResponse;
import com.aliyun.facebody20191230.models.BlurFaceResponseBody;
import com.heyu.api.alibaba.handle.facebody.ABlurFaceHandle;
import com.heyu.api.alibaba.request.facebody.ABlurFaceRequest;
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.card.CharacterRecognizeRequest;
import com.heyu.api.request.face.CharacterRecognizeReq;
import com.heyu.api.resp.face.CharacterRecognizeResp;
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/BlurFace?tab=DEMO&lang=JAVA&RegionId=cn-shanghai
 *
 *人脸信息脱敏
 *
 * BlurFace
 *功能描述
 * 人脸信息脱敏能力对输入图像中的人脸进行模糊处理，输出脱敏后的图像。
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/face")
@NotIntercept
public class BlurFaceController extends BaseController {


    @Autowired
    private ABlurFaceHandle aBlurFaceHandle;


    @RequestMapping("/mask")
    @CacheResult
    public R recognize(CharacterRecognizeReq request) {
        CharacterRecognizeResp resp = new CharacterRecognizeResp();
        ABlurFaceRequest aBlurFaceRequest = new ABlurFaceRequest();
        aBlurFaceRequest.setImageBase64(request.getImageBase64());
        aBlurFaceRequest.setImageUrl(request.getImageUrl());
        ApiR<BlurFaceResponse> aR = aBlurFaceHandle.handle(aBlurFaceRequest);
        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {

            BlurFaceResponseBody responseBody = aR.getData().getBody();
            BlurFaceResponseBody.BlurFaceResponseBodyData responseBodyData = responseBody.getData();


            resp.setOriginImageUrl(resp.getOriginImageUrl());
            resp.setMaskImageURL(resp.getMaskImageURL());

            return R.ok().setData(resp);
        }
        return R.error(aR.getErrorMsg());
    }


}
