package com.skr.mdm.controller;

import com.skr.mdm.dto.LoginAdminDTO;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.service.ClientAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author nfq
 * @date 2021/2/19 11:54
 */
@RestController
@RequestMapping("client/admin")
@Api(tags = "管理员客户端")
public class ClientAdminController {

    @Autowired
    private ClientAdminService clientAdminService;

    @PostMapping("permission")
    @ApiOperation("权限集合")
    public ResponseResult listPermission(@ApiIgnore Authentication authentication) {
        return ResponseResult.success(authentication.getAuthorities());
    }

    @PostMapping("info")
    @ApiOperation("管理员信息")
    public ResponseResult adminInfo(@ApiIgnore Authentication authentication) {
        LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
        return ResponseResult.success(loginAdminDTO.getAdminName());
    }

    @PostMapping("equipment/list")
    @ApiOperation("设备列表")
    public ResponseResult listEquipment(Integer pageNum, Integer pageSize, Integer searchType, String searchValue, @ApiIgnore Authentication authentication) {
        LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
        return clientAdminService.listEquipment(pageNum, pageSize, searchType, searchValue, loginAdminDTO);
    }

    @PostMapping("lock")
    @ApiOperation("锁屏")
    public ResponseResult lockCmd(@RequestParam String lockPassword, @RequestParam List<Integer> userIdList, @ApiIgnore Authentication authentication) {
        LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
        return clientAdminService.lockCmd(lockPassword, userIdList, loginAdminDTO);
    }

    @PostMapping("inform")
    @ApiOperation("通知")
    public ResponseResult informCmd(@RequestParam String inform, @RequestParam List<Integer> userIdList, @ApiIgnore Authentication authentication) {
        LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
        return clientAdminService.informCmd(inform, userIdList, loginAdminDTO);
    }

    @PostMapping("roll/call")
    @ApiOperation("点名")
    public ResponseResult rollCall(@RequestParam List<Integer> userIdList, @ApiIgnore Authentication authentication) {
        LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
        return clientAdminService.rollCall(userIdList, loginAdminDTO);
    }

    @PostMapping("bell")
    @ApiOperation("响铃")
    public ResponseResult bell(@RequestParam List<Integer> userIdList, @ApiIgnore Authentication authentication) {
        LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
        return clientAdminService.bell(userIdList, loginAdminDTO);
    }

    @PostMapping("unlock")
    @ApiOperation("解锁")
    public ResponseResult unlockCmd(@RequestParam List<Integer> userIdList, @ApiIgnore Authentication authentication) {
        LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
        return clientAdminService.unlockCmd(userIdList, loginAdminDTO);
    }

    @PostMapping("photo")
    @ApiOperation("拍照")
    public ResponseResult takePhotos(@RequestParam List<Integer> userIdList, @ApiIgnore Authentication authentication) {
        LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
        return clientAdminService.takePhotos(userIdList, loginAdminDTO);
    }

    @PostMapping("screen")
    @ApiOperation("截屏")
    public ResponseResult screenShot(@RequestParam List<Integer> userIdList, @ApiIgnore Authentication authentication) {
        LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
        return clientAdminService.screenShot(userIdList, loginAdminDTO);
    }

    @PostMapping("cmd/list")
    @ApiOperation("指令列表")
    public ResponseResult listLockCmd(Integer pageNum, Integer pageSize, @ApiParam(value = "1:操作类型 2：内容 3：时间 4：用户名") Integer searchType,
                                      String searchValue, @ApiIgnore Authentication authentication) {
        LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
        return clientAdminService.listLockCmd(pageNum, pageSize, searchType, searchValue, loginAdminDTO);
    }

    @PostMapping("cmd/user/list")
    @ApiOperation("指令作用人列表")
    public ResponseResult listUserLockCmd(String messageId, Integer pageNum, Integer pageSize,
                                          @ApiParam(value = "1:状态 2：用户名 3：部门 4：imei 5：用户手机号 6：设备手机号") Integer searchType,
                                          String searchValue, @ApiIgnore Authentication authentication) {
        LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
        return clientAdminService.listUserLockCmd(messageId, pageNum, pageSize, searchType, searchValue, loginAdminDTO);
    }
}
