package com.heyu.api.controller.face;


import com.aliyun.facebody20191230.models.RecognizeHandGestureResponse;
import com.aliyun.facebody20191230.models.RecognizeHandGestureResponseBody;
import com.heyu.api.alibaba.handle.facebody.ARecognizeHandGestureHandle;
import com.heyu.api.alibaba.request.facebody.ARecognizeHandGestureRequest;
import com.heyu.api.controller.BaseController;
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.RecognizeHandGestureReq;
import com.heyu.api.resp.face.RecognizeHandGestureResp;
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/RecognizeHandGesture?RegionId=cn-shanghai
 *
 *静态手势识别
 *
 * RecognizeHandGesture
 */
@Slf4j
@RestController
@RequestMapping("/hand/gesture")
@NotIntercept
public class RecognizeHandGestureController extends BaseController {


    @Autowired
    private ARecognizeHandGestureHandle arRecognizeHandGestureHandle;

    @RequestMapping("/recognize")
    public R recognize(RecognizeHandGestureReq req) {
        RecognizeHandGestureResp resp = new RecognizeHandGestureResp();

        ARecognizeHandGestureRequest arRecognizeHandGestureRequest = new ARecognizeHandGestureRequest();
        arRecognizeHandGestureRequest.setImageBase64(req.getImageBase64());
        arRecognizeHandGestureRequest.setImageUrl(req.getImageUrl());
        ApiR<RecognizeHandGestureResponse> aR = arRecognizeHandGestureHandle.handle(arRecognizeHandGestureRequest);
        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            RecognizeHandGestureResponseBody.RecognizeHandGestureResponseBodyData responseBodyData = aR.getData().getBody().getData();

            resp.setType(responseBodyData.getType());
            resp.setScore(responseBodyData.getScore());
            return R.ok().setData(resp);

        }
        return R.error();
    }
}


