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.EventEigDetailVO;
import com.njcn.cloud.pojo.vo.EventInfoDetailVO;
import com.njcn.cloud.pojo.vo.EventMsgDetailVO;
import com.njcn.cloud.pojo.vo.EventWaveDetailVO;
import com.njcn.cloud.service.IAppEventInfoService;
import com.njcn.cloud.service.IAppEventMsgService;
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 com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;



/**
 * @description: 暂态消息业务层
 * @author: denghuajun
 * @time: 2019-10-17 14:33:55
 **/
@RestController
@RequestMapping("/eventmsg")
@Api(tags = "暂态消息接口")
@RequiredArgsConstructor
@Slf4j
public class EventMsgController extends BaseController {

    private final IAppEventMsgService eventMsgService;
    private final IAppEventInfoService eventInfoService;

    /**
     * 暂态消息获取
     */
    @PostMapping("/eventDetailList")
    @ApiOperation(value = "暂态消息获取入口", notes = "暂态消息")
    public HttpResult<EventMsgDetailVO> eventDetailList(@RequestBody BaseParam param) {
        String methodDescribe = getMethodDescribe("eventDetailList");
        if (StrUtil.isBlank(param.getSearchValue())) {
            throw new BusinessException(EventMsgCodeEnum.USERID_WRONG.getMsg());
        }
        EventMsgDetailVO detailVO = eventMsgService.eventMsgPage(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, detailVO, methodDescribe);
    }

    /**
     * 暂态事件基本信息获取
     */
    @PostMapping("/eventDetailBaseInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "eventMsgIndex", value = "暂态消息id", required = true, paramType = "query"),
    })
    @ApiOperation(value = "暂态事件基本信息入口", notes = "暂态事件基本信息")
    public HttpResult<EventInfoDetailVO> eventDetailBaseInfo(String eventMsgIndex) {
        String methodDescribe = getMethodDescribe("eventDetailBaseInfo");
        if (StrUtil.isBlank(eventMsgIndex)) {
            throw new BusinessException(EventMsgCodeEnum.eventDetailIndex_WRONG.getMsg());
        }
        EventInfoDetailVO eventInfoList = eventMsgService.eventInfoDetail(eventMsgIndex);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, eventInfoList, methodDescribe);
    }

    /**
     * 暂态事件特征幅值
     */
    @PostMapping("/eventDetailEigenvalue")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "eventDetailIndex", value = "暂降事件id", required = true, paramType = "query"),
    })
    @ApiOperation(value = "暂态事件特征幅值入口", notes = "暂态事件特征幅值")
    public HttpResult<EventEigDetailVO.Detail> eventDetailEigenvalue(String eventDetailIndex) {
        String methodDescribe = getMethodDescribe("eventDetailEigenvalue");
        if (StrUtil.isBlank(eventDetailIndex)) {
            throw new BusinessException(EventMsgCodeEnum.eventDetailIndex_WRONG.getMsg());
        }
        EventEigDetailVO.Detail detail = eventInfoService.eventDetailEigenvalue(eventDetailIndex);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, detail, methodDescribe);


    }

    /**
     * 暂态事件波形图
     */
    @PostMapping("/eventDetailWave")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "eventDetailIndex", value = "暂降事件id", required = true, paramType = "query"),
    })
    @ApiOperation(value = "暂态事件波形图入口", notes = "暂态事件波形图")
    public HttpResult<EventWaveDetailVO> eventDetailWave(String eventDetailIndex) {
        String methodDescribe = getMethodDescribe("eventDetailWave");
        if (StrUtil.isBlank(eventDetailIndex)) {
            throw new BusinessException(EventMsgCodeEnum.eventDetailIndex_WRONG.getMsg());
        }
        EventWaveDetailVO vo = eventInfoService.eventDetailWave(eventDetailIndex);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
    }

    /**
     * 暂态评价
     */
    @PostMapping("/eventDetailEvaluate")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "eventDetailIndex", value = "暂降事件id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "evaluate", value = "暂态评价", required = true, paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, paramType = "query"),
    })
    @ApiOperation(value = "暂态评价入口", notes = "暂态评价获取")
    public HttpResult<Boolean> eventDetailEvaluate(String eventDetailIndex, int evaluate, String userId) {
        String methodDescribe = getMethodDescribe("eventDetailEvaluate");
        if (StrUtil.isBlank(eventDetailIndex)) {
            throw new BusinessException(EventMsgCodeEnum.eventDetailIndex_WRONG.getMsg());
        }
        Boolean aBoolean = eventInfoService.eventDetailEvaluate(eventDetailIndex, evaluate, userId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, aBoolean, methodDescribe);
    }


}