package com.huiju.estateagents.property.controller;


import com.huiju.estateagents.base.BaseController;
import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.center.taUser.entity.TaUser;
import com.huiju.estateagents.property.common.UserElement;
import com.huiju.estateagents.property.service.ITpEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 * 设备表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-04-15
 */
@RestController
@RequestMapping("/")
@Api(value = "设备表", description = "设备表")
public class TpEquipmentController extends BaseController {

    @Autowired
    private ITpEquipmentService iTpEquipmentService;

    @RequestMapping(value = "/equipment/list", method = RequestMethod.GET)
    @ApiOperation(value = "根据类型查询设备表", notes = "根据类型查询设备表")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "type", value = "1 监控 2 访客机 3 可是对讲"),
        @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    })
    public ResponseBean getAll(@RequestParam("type") Integer type, HttpServletRequest request) {
        ResponseBean responseBean = new ResponseBean();
        TaUser userElement = getTaUser(request);
        responseBean = iTpEquipmentService.getAllByCommunityAndEquipmentType(userElement, type);
        return responseBean;
    }


    @RequestMapping(value = "/equipment/monitoring", method = RequestMethod.POST)
    @ApiOperation(value = "添加或修改监控设备", notes = "添加或修改监控设备")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataTypeClass = Integer.class, name = "parameter", value = "监控设备数据"),
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    })
    public ResponseBean saveOrUpdateMonitoring(@RequestBody String parameter, HttpServletRequest request) {
        ResponseBean responseBean = new ResponseBean();
        TaUser userElement = getTaUser(request);
        responseBean = iTpEquipmentService.saveOrUpdateMonitoring(parameter, userElement);
        return responseBean;
    }

    @RequestMapping(value = "/equipment/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除设备", notes = "删除设备")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataTypeClass = Integer.class, name = "id", value = "设备id"),
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    })
    public ResponseBean deleteEquipmentById(@PathVariable("id") Integer id, HttpServletRequest request){
        ResponseBean responseBean = new ResponseBean();
        responseBean = iTpEquipmentService.deleteEquipmentById(id);
        return responseBean;
    }

    @RequestMapping(value = "/equipment/delete", method = RequestMethod.DELETE)
    @ApiOperation(value = "批量删除设备", notes = "批量删除设备")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataTypeClass = Integer.class, name = "ids", value = "设备id"),
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    })
    public ResponseBean deleteBachEquipmentById(@RequestBody List<Integer> ids, HttpServletRequest request){
        ResponseBean responseBean = new ResponseBean();
        responseBean = iTpEquipmentService.deleteBachEquipmentById(ids);
        return responseBean;
    }


    @RequestMapping(value = "/equipment/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据类型查询设备表", notes = "根据类型查询设备表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "type", value = "1 监控 2 访客机 3 可是对讲"),
            @ApiImplicitParam(paramType = "path", dataTypeClass = Integer.class, name = "id", value = "设备id"),
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    })
    public ResponseBean getMonitoringById(@RequestParam("type") Integer type, @PathVariable("id") Integer id, HttpServletRequest request) {
        ResponseBean responseBean = new ResponseBean();
        TaUser userElement = getTaUser(request);
        responseBean = iTpEquipmentService.getMonitoringById(userElement, type, id);
        return responseBean;
    }

}
