package com.css.simulation.resource.server.adapter.controller.model_library.sensor_configuration;


import api.common.pojo.common.ResponseBodyVO;
import api.common.pojo.constants.LogConstants;
import api.common.pojo.param.model.LidarParam;
import api.common.pojo.po.model.LidarPO;
import api.common.pojo.vo.model.LidarVO;
import api.common.util.ObjectUtil;
import com.css.simulation.resource.server.app.service.LidarService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping(value = "/lidar", name = LogConstants.MODULE_LIDAR)
public class SensorLidarController {

    @Resource
    private LidarService lidarService;

    /**
     * 获取列表
     */
    @RequestMapping("/getLidarList")
    @ResponseBody
    public ResponseBodyVO<List<LidarVO>> getLidarList(@RequestBody LidarParam lidarParam) {
        ResponseBodyVO<List<LidarVO>> response = new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(lidarService.getLidarList(lidarParam));
        return response;
    }

    /**
     * 获取私有列表
     */
    @RequestMapping("/getMyLidarList")
    @ResponseBody
    public ResponseBodyVO<List<LidarVO>> getMyLidarList(@RequestBody LidarParam lidarParam) {
        ResponseBodyVO<List<LidarVO>> response = new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(lidarService.getMyLidarList(lidarParam));
        return response;
    }
    /**
     * 获取私有列表
     */
    @RequestMapping("/getMyLidarListNew")
    @ResponseBody
    public ResponseBodyVO<List<LidarVO>> getMyLidarListNew(@RequestBody LidarParam lidarParam) {
        ResponseBodyVO<List<LidarVO>> response = new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(lidarService.getMyLidarList1(lidarParam));
        return response;
    }

    /**
     * 根据id获取详情
     */
    @RequestMapping("/getLidarInfo")
    @ResponseBody
    public ResponseBodyVO<LidarVO> getLidarInfo(@RequestBody LidarParam lidarParam) {
        ResponseBodyVO<LidarVO> response = new ResponseBodyVO<LidarVO>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(lidarService.getLidarInfo(lidarParam));
        return response;
    }

    /**
     * 新增、修改、另存为
     */
    @RequestMapping("/saveLidar")
    @ResponseBody
    public ResponseBodyVO<LidarPO> saveLidar(@RequestBody LidarPO lidarPO) {
        if (ObjectUtil.isNull(lidarPO)) {
            return new ResponseBodyVO<>(false, 500, "参数必传！", null);
        }
        ResponseBodyVO<LidarPO> response = new ResponseBodyVO<LidarPO>(ResponseBodyVO.Response.SUCCESS);
        LidarPO po = lidarService.saveLidar(lidarPO);
        if (ObjectUtil.isNull(po.getId())) {
            return new ResponseBodyVO<>(false, 500, "传感器名称重复！", null);
        }
        response.setInfo(po);
        return response;
    }

    /**
     * 分享
     */
    @RequestMapping("/shareLidar")
    @ResponseBody
    @PreAuthorize("@AuthorityCheck.admin()")
    public ResponseBodyVO<LidarPO> shareLidar(@RequestBody LidarPO lidarPO) {
        if (ObjectUtil.isNull(lidarPO)) {
            return new ResponseBodyVO<>(false, 500, "参数必传！", null);
        }
        ResponseBodyVO<LidarPO> response = new ResponseBodyVO<LidarPO>(ResponseBodyVO.Response.SUCCESS);
        LidarPO po = lidarService.shareLidar(lidarPO);
        if (ObjectUtil.isNull(po.getId())) {
            return new ResponseBodyVO<>(false, 500, "传感器名称重复！", null);
        }
        response.setInfo(po);
        return response;
    }

    /**
     * 删除
     */
    @RequestMapping("/delLidarById")
    @ResponseBody
    public ResponseBodyVO<Void> delLidarById(@RequestBody LidarPO lidarPO) {
        lidarService.delLidarById(lidarPO);
        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
    }
}
