package com.cmvr.web.controller.api;

import com.alibaba.fastjson2.JSON;
import com.cmvr.common.core.controller.BaseController;
import com.cmvr.common.core.domain.AjaxResult;
import com.cmvr.edge.client.model.biohead.EdgeFacialExpressionVO;
import com.cmvr.edge.client.service.EdgeBioHeadService;
import com.cmvr.edge.client.service.EdgeDexHandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "边缘--机器人灵巧手")
@RestController
@RequestMapping("/api/dexHand")
@RequiredArgsConstructor
public class EdgeDexHandController extends BaseController {

    private final EdgeDexHandService edgeDexHandService;

    @ApiOperation("获取灵巧手状态信息")
    @GetMapping("/status")
    public AjaxResult status(
            @RequestParam("deviceId") String deviceId,
            @RequestParam("terminalId") String terminalId
    ) {
        return success(JSON.parseObject(JSON.toJSONString(edgeDexHandService.getStatus(terminalId, deviceId)), Map.class));
    }


    @ApiOperation("设置灵巧手弯曲角度")
    @GetMapping("/angle")
    public AjaxResult setAngle(
            @RequestParam("deviceId") String deviceId,
            @RequestParam("terminalId") String terminalId,
            @RequestParam("id") int id,
            @RequestParam("value") float value
    ) {
        edgeDexHandService.setDexHandAngle(terminalId, deviceId, id, value);
        return success("ok");
    }


    @ApiOperation("获取灵巧手按压力信息")
    @GetMapping("/sensor")
    public AjaxResult sensor(
            @RequestParam("deviceId") String deviceId,
            @RequestParam("terminalId") String terminalId
    ) {
        return success(JSON.parseObject(edgeDexHandService.getSensorData(terminalId, deviceId), Map.class));
    }
}
