package com.njcn.cloud.controller.information;

import cn.hutool.core.util.StrUtil;
import com.njcn.cloud.enums.app.EventMsgCodeEnum;
import com.njcn.cloud.pojo.vo.DevComTJ;
import com.njcn.cloud.pojo.vo.DevMsgDetailInfo;
import com.njcn.cloud.service.IAppDevMsgService;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.pq.pojo.vo.DevDetail;
import com.njcn.web.controller.BaseController;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 终端消息业务层
 * @Author: wr
 * @Date: 2023/11/7 10:52
 */
@RestController
@RequestMapping("/deviceMsg")
@Api(tags = "终端状态信息接口")
@RequiredArgsConstructor
public class DevMsgController extends BaseController {


    private final IAppDevMsgService devMsgService;

//    /**
//     * 终端消息列表获取
//     */
//    @PostMapping("/deviceMsgList")
//    @Deprecated
//    @ApiOperation(value = "终端消息列表入口", notes = "终端消息列表")
//    public HttpResult<Page<AppDevMsg>> deviceMsgList(@RequestBody BaseParam param) {
//        String methodDescribe = getMethodDescribe("deviceMsgList");
//        if (StrUtil.isBlank(param.getSearchValue())) {
//            throw new BusinessException(EventMsgCodeEnum.USERID_WRONG.getMsg());
//        }
//        Page<AppDevMsg> page = devMsgService.deviceMsgList(param);
//        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
//    }

    /**
     * 终端列表获取
     */
    @PostMapping("/deviceList")
    @ApiOperation(value = "终端列表入口", notes = "终端列表")
    public HttpResult<DevMsgDetailInfo> deviceList(@RequestBody BaseParam param) {
        String methodDescribe = getMethodDescribe("deviceList");
        if (StrUtil.isBlank(param.getSearchValue())) {
            throw new BusinessException(EventMsgCodeEnum.USERID_WRONG.getMsg());
        }
        DevMsgDetailInfo devMsgDetailInfo = devMsgService.deviceList(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, devMsgDetailInfo, methodDescribe);
    }

    /**
     * 修改消息状态
     */
    @PostMapping("/updateDevMsgState")
    @ApiOperation(value = "修改消息状态", notes = "消息状态")
    public HttpResult<Boolean> updateDevMsgState(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("updateDevMsgState");
        Boolean aBoolean = devMsgService.updateDevMsgState(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, aBoolean, methodDescribe);
    }

    /**
     * 终端通讯状态统计
     */
    @PostMapping("/devComTJ")
    @ApiOperation(value = "终端通讯状态统计", notes = "终端通讯状态统计")
    public HttpResult<DevComTJ> getDevComTJ(String deptId) {
        String methodDescribe = getMethodDescribe("getDevComTJ");
        DevComTJ devComTJ = devMsgService.getDevComTJ(deptId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, devComTJ, methodDescribe);
    }

    /**
     * 终端通讯信息
     */
    @PostMapping("/devComInfo")
    @ApiOperation(value = "终端通讯信息", notes = "终端通讯信息")
    public HttpResult<List<DevDetail>> getDevComInfo(String deptId) {
        String methodDescribe = getMethodDescribe("getDevComInfo");
        List<DevDetail> devComInfo = devMsgService.getDevComInfo(deptId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, devComInfo, methodDescribe);
    }


}