package com.njcn.gather.detection.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.response.HttpResult;
import com.njcn.gather.detection.sntp.SntpServerManager;
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.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags = "SNTP对时")
@RestController
@RequestMapping("/sntp")
@RequiredArgsConstructor
public class SntpController extends BaseController {

    private final SntpServerManager sntpServerManager;

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/start")
    @ApiOperation("启动SNTP对时服务")
    public HttpResult<?> start() {
        String methodDescribe = getMethodDescribe("start");
        sntpServerManager.start();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/stop")
    @ApiOperation("停止SNTP对时服务")
    public HttpResult<?> stop() {
        String methodDescribe = getMethodDescribe("stop");
        sntpServerManager.stop();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }
}
