package com.njcn.gather.event.eventlist.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
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.LogUtil;
import com.njcn.gather.event.eventlist.pojo.param.EventListQueryParam;
import com.njcn.gather.event.eventlist.pojo.param.EventWaveExportParam;
import com.njcn.gather.event.eventlist.pojo.vo.EventListVO;
import com.njcn.gather.event.eventlist.service.EventListService;
import com.njcn.gather.tool.wave.pojo.vo.WaveComtradeResultVO;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.HttpResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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;

/**
 * 事件列表接口预留入口。
 */
@Validated
@Slf4j
@Api(tags = "事件列表")
@RestController
@RequestMapping("/event/list")
@RequiredArgsConstructor
public class EventListController extends BaseController {

    /** 事件列表服务。 */
    private final EventListService eventListService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("分页查询暂态事件列表")
    @PostMapping("/transient/page")
    public HttpResult<Page<EventListVO>> pageTransientEvents(@RequestBody EventListQueryParam param) {
        String methodDescribe = getMethodDescribe("pageTransientEvents");
        LogUtil.njcnDebug(log, "{}，开始分页查询暂态事件列表，param={}", methodDescribe, param);
        Page<EventListVO> result = eventListService.pageTransientEvents(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("查询暂态事件详情")
    @GetMapping("/transient/{eventId}")
    public HttpResult<EventListVO> getTransientEventDetail(@PathVariable("eventId") String eventId) {
        String methodDescribe = getMethodDescribe("getTransientEventDetail");
        LogUtil.njcnDebug(log, "{}，开始查询暂态事件详情，eventId={}", methodDescribe, eventId);
        EventListVO result = eventListService.getTransientEventDetail(eventId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
    @ApiOperation("导出暂态事件列表")
    @PostMapping("/transient/export")
    public void exportTransientEvents(@RequestBody EventListQueryParam param) {
        eventListService.exportTransientEvents(param);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("查看暂态事件波形")
    @GetMapping("/transient/{eventId}/wave")
    public HttpResult<WaveComtradeResultVO> getTransientEventWave(@PathVariable("eventId") String eventId) {
        String methodDescribe = getMethodDescribe("getTransientEventWave");
        LogUtil.njcnDebug(log, "{}，开始查看暂态事件波形，eventId={}", methodDescribe, eventId);
        WaveComtradeResultVO result = eventListService.getTransientEventWave(eventId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
    @ApiOperation("导出选中暂态事件波形")
    @PostMapping("/transient/wave/export")
    public void exportTransientEventWaves(@RequestBody EventWaveExportParam param) {
        eventListService.exportTransientEventWaves(param);
    }
}
