package com.yihu.hos.controllers;

import com.yihu.hos.services.ServerMonitorService;
import com.yihu.hos.web.framework.model.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/server")
public class ServerMonitorController {
    @Resource(name = ServerMonitorService.BEAN_ID)
    private ServerMonitorService serverMonitorService;

    @RequestMapping(value = "/bandwidth", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "获取带宽", produces = "application/json", notes = "获取带宽")
    public Result bandwidth(
            @ApiParam(name = "beginTime", value = "开始时间", required = true)
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
        return serverMonitorService.bandwidth(beginTime, endTime);
    }

    @RequestMapping(value = "/qps", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "获取吞吐量", produces = "application/json", notes = "获取吞吐量")
    public Result qps(
            @ApiParam(name = "beginTime", value = "开始时间", required = true)
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
        return serverMonitorService.qps(beginTime, endTime);
    }

    @RequestMapping(value = "/usage", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "获取使用率", produces = "application/json", notes = "获取使用率")
    public Result usage(
            @ApiParam(name = "beginTime", value = "开始时间", required = true)
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
        return serverMonitorService.usage(beginTime, endTime);
    }

    @RequestMapping(value = "/delay", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "获取延时", produces = "application/json", notes = "获取延时")
    public Result delay(
            @ApiParam(name = "beginTime", value = "开始时间", required = true)
            @RequestParam(value = "beginTime") String beginTime,
            @ApiParam(name = "endTime", value = "结束时间", required = true)
            @RequestParam(value = "endTime") String endTime) {
        return serverMonitorService.delay(beginTime, endTime);
    }
}
