package com.njcn.gather.systemmonitor.disk.controller;

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.systemmonitor.disk.pojo.param.DiskMonitorParam;
import com.njcn.gather.systemmonitor.disk.service.IDiskMonitorNotifyService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.HttpResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 磁盘监控通知接口。
 */
@Validated
@Slf4j
@Api(tags = "磁盘监控通知")
@RestController
@RequestMapping("/disk-monitor")
@RequiredArgsConstructor
public class DiskMonitorNotifyController extends BaseController {

    private final IDiskMonitorNotifyService diskMonitorNotifyService;

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
    @PostMapping("/notify/test")
    @ApiOperation("测试磁盘监控通知")
    @ApiImplicitParam(name = "param", value = "通知测试参数", required = true)
    public HttpResult<Boolean> testNotify(@RequestBody @Valid DiskMonitorParam.NotifyTestParam param) {
        String methodDescribe = getMethodDescribe("testNotify");
        LogUtil.njcnDebug(log, "{}，测试磁盘监控通知，driveLetter={}", methodDescribe, param.getDriveLetter());
        boolean result = diskMonitorNotifyService.testNotify(param);
        return HttpResultUtil.assembleCommonResponseResult(result ? CommonResponseEnum.SUCCESS : CommonResponseEnum.FAIL, result, methodDescribe);
    }
}
