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.GpsParam;
import api.common.pojo.po.model.GpsPO;
import api.common.pojo.vo.model.GpsVO;
import api.common.util.ObjectUtil;
import com.css.simulation.resource.server.app.service.GpsService;
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 = "/gps", name = LogConstants.MODULE_GPS)
public class SensorGpsController {

    @Resource
    private GpsService gpsService;


    //* -------------------------------- 删除 GPS --------------------------------
    @RequestMapping("/delGpsById")
    public ResponseBodyVO<String> delGpsById(@RequestBody GpsPO gpsPO) {
        gpsService.delGpsById(gpsPO);
        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
    }

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

    /**
     * 获取列表
     */
    @RequestMapping("/getGpsList")
    public ResponseBodyVO<List<GpsVO>> getGpsList(@RequestBody GpsParam gpsParam) {
        ResponseBodyVO<List<GpsVO>> response = new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(gpsService.getGpsList(gpsParam));
        return response;
    }

    /**
     * 获取私有列表
     */
    @RequestMapping("/getMyGpsList")
    public ResponseBodyVO<List<GpsVO>> getMyCameraList(@RequestBody GpsParam gpsParam) {
        ResponseBodyVO<List<GpsVO>> response = new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(gpsService.getMyGpsList(gpsParam));
        return response;
    }
    /**
     * 获取私有列表
     */
    @RequestMapping("/getMyGpsListNew")
    public ResponseBodyVO<List<GpsVO>> getMyGpsListNew(@RequestBody GpsParam gpsParam) {
        ResponseBodyVO<List<GpsVO>> response = new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(gpsService.getGpsList1(gpsParam));
        return response;
    }

    /**
     * 根据id获取详情
     */
    @RequestMapping("/getGpsInfo")
    public ResponseBodyVO<GpsVO> getGpsInfo(@RequestBody GpsParam gpsParam) {
        ResponseBodyVO<GpsVO> response = new ResponseBodyVO<GpsVO>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(gpsService.getGpsInfo(gpsParam));
        return response;
    }

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

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


}
