package com.njcn.device.pq.controller;

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.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.pq.pojo.param.AlarmStrategyParam;
import com.njcn.device.pq.pojo.vo.AlarmStrategyVO;
import com.njcn.device.pq.service.AlarmStrategyService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version 1.0.0
 * @author: chenchao
 * @date: 2022/06/23 11:36
 */
@Validated
@Slf4j
@RestController
@RequestMapping("/Alarm")
@Api(tags = "告警管理")
@AllArgsConstructor
public class AlarmController extends BaseController {

    private final AlarmStrategyService alarmStrategyService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getAlarmStrategyData")
    @ApiOperation("告警策略管理")
    public HttpResult<List<AlarmStrategyVO>> getAlarmStrategyData(){
        String methodDescribe = getMethodDescribe("getAlarmStrategyData");
        List<AlarmStrategyVO> list = alarmStrategyService.getAlarmStrategyData();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/updateAlarmStrategyById")
    @ApiOperation("修改告警策略")
    @ApiImplicitParam(name = "alarmStrategyParam", value = "修改策略参数", required = true)
    public HttpResult<List<AlarmStrategyVO>> updateAlarmStrategyById(@RequestBody AlarmStrategyParam alarmStrategyParam){
        String methodDescribe = getMethodDescribe("getAlarmStrategyData");
        boolean res = alarmStrategyService.updateAlarmStrategyById(alarmStrategyParam);
        if (res) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            throw new BusinessException(CommonResponseEnum.FAIL);
        }
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/addAlarmStrategyById")
    @ApiOperation("新增告警策略")
    @ApiImplicitParam(name = "alarmStrategyParam", value = "新增策略参数", required = true)
    public HttpResult<List<AlarmStrategyVO>> addAlarmStrategyById(@RequestBody AlarmStrategyParam alarmStrategyParam){
        String methodDescribe = getMethodDescribe("addAlarmStrategyById");
        boolean res = alarmStrategyService.addAlarmStrategyById(alarmStrategyParam);
        if (res) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            throw new BusinessException(CommonResponseEnum.FAIL);
        }
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/removeAlarmStrategyData")
    @ApiOperation("删除告警策略")
    @ApiImplicitParam(name = "id", value = "策略id", required = true)
    public HttpResult<List<AlarmStrategyVO>> removeAlarmStrategyData(@RequestParam("id") String id){
        String methodDescribe = getMethodDescribe("removeAlarmStrategyData");
        boolean res = alarmStrategyService.removeAlarmStrategyData(id);
        if (res) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            throw new BusinessException(CommonResponseEnum.FAIL);
        }
    }

}
