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.CameraParam;
import api.common.pojo.po.model.CameraPO;
import api.common.pojo.vo.model.CameraVO;
import api.common.util.ObjectUtil;
import com.css.simulation.resource.server.app.service.CameraService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
@RequestMapping(value = "/camera", name = LogConstants.MODULE_CAMERA)
public class SensorCameraController {

    @Resource
    private CameraService cameraService;


    //* -------------------------------- 删除摄像头 --------------------------------

    /**
     * 删除
     */
    @RequestMapping("/delCameraById")
    public ResponseBodyVO<String> delCameraById(@RequestBody CameraPO cameraPO) {
        cameraService.delCameraById(cameraPO);
        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
    }

    //* -------------------------------- Comment --------------------------------

    /**
     * 获取列表
     */
    @RequestMapping("/getCameraList")
    public ResponseBodyVO<List<CameraVO>> getCameraList(@RequestBody CameraParam cameraParam) {
        ResponseBodyVO<List<CameraVO>> response = new ResponseBodyVO<List<CameraVO>>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(cameraService.getCameraList(cameraParam));
        return response;
    }

    /**
     * 获取私有列表
     */
    @RequestMapping("/getMyCameraList")
    public ResponseBodyVO<List<CameraVO>> getMyCameraList(@RequestBody CameraParam cameraParam) {
        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, cameraService.getMyCameraList(cameraParam));
    }
    /**
     * 获取私有列表
     */
    @RequestMapping("/getMyCameraListNew")
    public ResponseBodyVO<List<CameraVO>> getMyCameraListNew(@RequestBody CameraParam cameraParam) {
        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, cameraService.getMyCameraList1(cameraParam));
    }


    /**
     * 根据id获取详情
     */
    @RequestMapping("/getCameraInfo")
    public ResponseBodyVO<CameraVO> getCameraInfo(@RequestBody CameraParam cameraParam) {
        ResponseBodyVO<CameraVO> response = new ResponseBodyVO<CameraVO>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(cameraService.getCameraInfo(cameraParam));
        return response;
    }

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

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

}
