package cn.iocoder.yudao.module.system.controller.admin.path;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.controller.admin.positionmap.vo.PositionMapItemRespVO;
import cn.iocoder.yudao.module.system.controller.admin.positionmap.vo.PositionMapItemSaveReqVO;
import cn.iocoder.yudao.module.system.controller.admin.positionmap.vo.PositionMapLineSaveReqVO;
import cn.iocoder.yudao.module.system.controller.admin.positionmap.vo.PositionMapSaveReqVO;
import cn.iocoder.yudao.module.system.controller.admin.robot.vo.RobotInformationSaveReqVO;
import cn.iocoder.yudao.module.system.service.path.PathPlanningService;
import cn.iocoder.yudao.module.system.service.tool.ToolsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 路径规划")
@RestController
@RequestMapping("/system/path/planning")
@Validated
public class PathPlanningController {

    @Resource
    private PathPlanningService pathPlanningService;

    @Resource
    private ToolsService toolsService;

    @PostMapping("/line/all")
    @Operation(summary = "同步ware_position_map_line的点位信息")
    @PreAuthorize("@ss.hasPermission('robot:information:synchronousPoint')")
    public CommonResult<String> synchronousPoint(@RequestBody PositionMapSaveReqVO positionMapSaveReqVO) {
        pathPlanningService.synchronousPoint(positionMapSaveReqVO);
        return success("同步完成");
    }

    @PostMapping("/line/add")
    @Operation(summary = "添加ware_position_map_line的点位信息")
    @PreAuthorize("@ss.hasPermission('robot:information:synchronousLineAdd')")
    public CommonResult<String> synchronousLineAdd(@RequestBody PositionMapLineSaveReqVO data) {
        pathPlanningService.synchronousLineAdd(data);
        return success("同步完成");
    }

    @PostMapping("/line/delete")
    @Operation(summary = "删除ware_position_map_line的点位信息")
    @PreAuthorize("@ss.hasPermission('robot:information:synchronousLineDelete')")
    public CommonResult<String> synchronousLineDelete(@RequestBody PositionMapLineSaveReqVO data) {
        pathPlanningService.synchronousLineDelete(data);
        return success("同步完成");
    }

    @PostMapping("/line/update")
    @Operation(summary = "更新ware_position_map_line的点位信息")
    @PreAuthorize("@ss.hasPermission('robot:information:synchronousLineUpdate')")
    public CommonResult<String> synchronousLineUpdate(@RequestBody PositionMapLineSaveReqVO data) {
        pathPlanningService.synchronousLineUpdate(data);
        return success("同步完成");
    }

    @PostMapping("/item/all")
    @Operation(summary = "同步ware_position_map_item的点位信息")
    @PreAuthorize("@ss.hasPermission('robot:information:synchronousItem')")
    public CommonResult<String> synchronousAllItem(@RequestBody PositionMapSaveReqVO positionMapSaveReqVO) {
        pathPlanningService.synchronousAllItem(positionMapSaveReqVO);
        return success("同步完成");
    }

    @PostMapping("/item/add")
    @Operation(summary = "添加ware_position_map_item的点位信息")
    @PreAuthorize("@ss.hasPermission('robot:information:synchronousItemAdd')")
    public CommonResult<String> synchronousAllItemAdd(@RequestBody PositionMapItemSaveReqVO positionMapItemSaveReqVO) {
        pathPlanningService.synchronousAllItemAdd(positionMapItemSaveReqVO);
        return success("同步完成");
    }

    @PostMapping("/item/delete")
    @Operation(summary = "删除ware_position_map_item的点位信息")
    @PreAuthorize("@ss.hasPermission('robot:information:synchronousItemDelete')")
    public CommonResult<String> synchronousItemDelete(@RequestBody PositionMapItemSaveReqVO positionMapItemSaveReqVO) {
        pathPlanningService.synchronousItemDelete(positionMapItemSaveReqVO);
        return success("同步完成");
    }

    @PostMapping("/item/update")
    @Operation(summary = "更新ware_position_map_item的点位信息")
    @PreAuthorize("@ss.hasPermission('robot:information:synchronousItemUpdate')")
    public CommonResult<String> synchronousItemUpdate(@RequestBody PositionMapItemSaveReqVO positionMapItemSaveReqVO) {
        pathPlanningService.synchronousItemUpdate(positionMapItemSaveReqVO);
        return success("同步完成");
    }

    @PostMapping("/sortConfig")
    @Operation(summary = "发送时间、优先级、距离的权重给PP")
    public CommonResult<String> sortConfig() {
        return success(toolsService.sendPPsortConfig());
    }

    @PostMapping("/robot/dimensions")
    @Operation(summary = "发送车辆编号对应的车宽、中心与车头距离、中心与车尾距离给PP")
    public CommonResult<String> robotDimensions() {
        pathPlanningService.robotDimensions();
        return success("同步完成");
    }

    @PostMapping("/robot/simulationRobotPoseRequest")
    @Operation(summary = "发送车辆数据给--仿真")
    public CommonResult<String> simulationRobotPoseRequest() {
        pathPlanningService.simulationRobotPoseRequest();
        return success("同步完成");
    }
}
