package com.njcn.csdevice.controller.message;


import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.param.DeviceMessageParam;
import com.njcn.csdevice.param.LineInfoParam;
import com.njcn.csdevice.service.DeviceMessageService;
import com.njcn.user.pojo.po.User;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 详细数据表 前端控制器
 * </p>
 *
 * @author xuyang
 * @since 2023-05-31
 */
@Slf4j
@RestController
@RequestMapping("/deviceMessage")
@Api(tags = "App消息推送管理")
@AllArgsConstructor
public class DeviceMessageController extends BaseController {

    private final DeviceMessageService deviceMessageService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getEventUserByDeviceId")
    @ApiOperation("根据设备获取需要推送的用户id")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "devId", value = "设备id", required = true, paramType = "query"),
        @ApiImplicitParam(name = "isAdmin", value = "是否需要推送给普通用户", required = true, paramType = "query")
    })
    public HttpResult<List<String>> getEventUserByDeviceId(@RequestParam("devId") String devId, @RequestParam("isAdmin") Boolean isAdmin){
        String methodDescribe = getMethodDescribe("getEventUserByDeviceId");
        List<String> list = deviceMessageService.getEventUserByDeviceId(devId,isAdmin);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getSendUserByType")
    @ApiOperation("根据事件类型和用户id查询打开推送的用户信息")
    @ApiImplicitParam(name = "param", value = "参数", required = true, paramType = "query")
    public HttpResult<List<User>> getSendUserByType(@RequestBody DeviceMessageParam param){
        String methodDescribe = getMethodDescribe("getSendUserByType");
        List<User> list = deviceMessageService.getSendUserByType(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineInfo")
    @ApiOperation("获取监测点信息")
    @ApiImplicitParam(name = "param", value = "参数", required = true)
    public HttpResult<String> getLineInfo(@RequestBody LineInfoParam param){
        String methodDescribe = getMethodDescribe("getLineInfo");
        deviceMessageService.getLineInfo(param.getNDid(),param.getList());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "success", methodDescribe);
    }

}

