package com.ningdatech.carapi.car.monitor.controller;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.carapi.car.monitor.manage.StatusMonitorManage;
import com.ningdatech.carapi.car.monitor.model.dto.LoadMonitorPageParamDTO;
import com.ningdatech.carapi.car.monitor.model.dto.SecurityMonitorPageParamDTO;
import com.ningdatech.carapi.car.monitor.model.vo.AlarmDataLoadVO;
import com.ningdatech.carapi.car.monitor.model.vo.SecurityMonitorVO;
import com.ningdatech.carapi.common.util.ExcelDownUtil;
import com.ningdatech.carapi.sys.entity.dto.CascadeCodeDTO;
import com.ningdatech.log.annotation.WebLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * @Classname SecurityMonitorController
 * @Description
 * @Date 2022/11/4 16:30
 * @Created by PoffyZhang
 */
@RestController
@RequestMapping(value = "/api/v1/car-manage/status-monitor")
@Api(tags = "车辆管理-状态监控")
@Validated
@RequiredArgsConstructor
public class StatusMonitorController {

    private final StatusMonitorManage statusMonitorManage;

    @ApiOperation("安全监控")
    @GetMapping("/security-monitor-list")
    public PageVo<SecurityMonitorVO> securityMonitorList(
            @Valid @ModelAttribute SecurityMonitorPageParamDTO param) {
        return statusMonitorManage.securityMonitorList(param);
    }

    @ApiOperation("告警事件类型列表")
    @GetMapping("/alarm-types")
    public List<CascadeCodeDTO> alarmTypes() {
        return statusMonitorManage.alarmTypes();
    }

    @ApiOperation("载重监控")
    @GetMapping("/load-monitor-list")
    public PageVo<AlarmDataLoadVO> loadMonitorList(
            @Valid @ModelAttribute LoadMonitorPageParamDTO param) {
        return statusMonitorManage.loadMonitorList(param);
    }

    @ApiOperation(value = "安全监控导出", notes = "安全监控导出")
    @GetMapping("/export-security-monitor")
    @WebLog
    public void exportSecurityMonitor(SecurityMonitorPageParamDTO req, HttpServletResponse response) {
        ExcelDownUtil.downXls(response, req, statusMonitorManage::exportSecurityMonitor);
    }

    @ApiOperation(value = "载重监控导出", notes = "载重监控导出")
    @GetMapping("/export-load-monitor")
    @WebLog
    public void exportLoadMonitor(LoadMonitorPageParamDTO req, HttpServletResponse response) {
        ExcelDownUtil.downXls(response, req, statusMonitorManage::exportLoadMonitor);
    }
}
