package com.njcn.cloud.controller.message;

import cn.hutool.core.util.StrUtil;
import com.njcn.cloud.enums.app.UserCodeEnum;
import com.njcn.cloud.service.MsgService;
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.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.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



/**
 * @author hongawen
 * @date: 2019/11/11 14:51
 */
@RestController
@RequestMapping("/msg")
@Api(tags = "内部消息推送")
@RequiredArgsConstructor
public class EventMsgPushController extends BaseController {

    private final MsgService msgService;

    /**
     * 暂态消息推送
     */
    @PostMapping("/sendEventMsg")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "eventDetailIndex", value = "暂降索引", required = true, paramType = "query"),
            @ApiImplicitParam(name = "lineId", value = "监测点索引", required = true, paramType = "query"),
    })
    @ApiOperation(value = "暂态消息推送", notes = "暂态消息推送")
    public HttpResult<Boolean> sendEventMsg(String eventDetailIndex, String lineId) throws Exception {
        String methodDescribe = getMethodDescribe("sendEventMsg");
        if (StrUtil.isBlank(eventDetailIndex) || StrUtil.isBlank(lineId)) {
            throw new BusinessException(UserCodeEnum.INVALID_PARAMETER.getMsg());
        }
        msgService.sendEventMsg(eventDetailIndex, lineId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }

    /**
     * 稳态消息推送
     */
    @PostMapping("/sendSteadyMsg")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userIndex", value = "用户索引", required = true, paramType = "query"),
            @ApiImplicitParam(name = "timeID", value = "统计时间", required = true, paramType = "query"),
            @ApiImplicitParam(name = "lineNum", value = "监测点个数", required = true, paramType = "query"),
    })
    @ApiOperation(value = "稳态消息推送", notes = "稳态消息推送")
    public HttpResult<Boolean> sendSteadyMsg(String userIndex, String timeID, Integer lineNum) {
        String methodDescribe = getMethodDescribe("sendSteadyMsg");
        if (StrUtil.isBlank(userIndex) || StrUtil.isBlank(userIndex)) {
            throw new BusinessException(UserCodeEnum.INVALID_PARAMETER.getMsg());
        }
        msgService.sendSteadyMsg(userIndex, timeID, lineNum);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }


    /**
     * 终端消息推送
     */
    @PostMapping("/sendTargetMsg")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userIndex", value = "用户索引", required = true, paramType = "query"),
            @ApiImplicitParam(name = "timeID", value = "统计时间", required = true, paramType = "query"),
            @ApiImplicitParam(name = "topID", value = "终端消息id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "flag", value = "强制推送标志", required = true, paramType = "query"),
    })
    @ApiOperation(value = "终端消息推送", notes = "终端消息推送")
    public HttpResult<Boolean> sendTargetMsg(String userIndex, String timeID, String topID, int flag) {
        String methodDescribe = getMethodDescribe("sendTargetMsg");
        if (StrUtil.isBlank(userIndex) || StrUtil.isBlank(userIndex)) {
            throw new BusinessException(UserCodeEnum.INVALID_PARAMETER.getMsg());
        }
        msgService.sendTargetMsg(userIndex, timeID, topID, flag);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }

}
