package com.microservices.mon.k8s.controller;

import com.alibaba.fastjson2.JSONObject;
import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.web.domain.GenericsAjaxResult;
import com.microservices.common.core.web.page.GenericsTableDataInfo;
import com.microservices.mon.k8s.domain.*;
import com.microservices.mon.k8s.domain.vo.ApplicationEnvTypeVo;
import com.microservices.mon.k8s.domain.vo.ApplicationTypeVo;
import com.microservices.mon.k8s.service.IMicroManagementService;
import com.microservices.mon.k8s.service.IMicroStatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("microStatus")
@Api(tags = "微服务状态监控")
@RefreshScope
public class MicroStatusController extends BaseController {
    @Autowired
    private IMicroStatusService microStatusService;

    @ApiOperation(value = "获取容器启停状态")
    @GetMapping("/podStartStopStatus")
    public GenericsAjaxResult<K8sPodStartStopStatus> getPodStartStopStatus() {
        return GenericsAjaxResult.success(microStatusService.getPodStartStopStatus());
    }

    @ApiOperation(value = "获取容器CPU使用率")
    @GetMapping("/podCpuUsage")
    public GenericsTableDataInfo<K8sPodContainerMetric> getPodCpuUsage(@RequestParam(value = "step", required = false) @ApiParam(value = "统计频率") Long step) {
        return new GenericsTableDataInfo<>(microStatusService.getPodCpuUsage(step));
    }

    @ApiOperation(value = "获取容器内存使用情况")
    @GetMapping("/podMemoryUsage")
    public GenericsTableDataInfo<K8sPodContainerMetric> getPodMemoryUsage(@RequestParam(value = "step", required = false) @ApiParam(value = "统计频率") Long step) {
        return new GenericsTableDataInfo<>(microStatusService.getPodMemoryUsage(step));
    }

    @ApiOperation(value = "获取容器硬盘读取情况")
    @GetMapping("/podDiskReads")
    public GenericsTableDataInfo<K8sPodContainerMetric> getPodDiskReads(@RequestParam(value = "step", required = false) @ApiParam(value = "统计频率") Long step) {
        return new GenericsTableDataInfo<>(microStatusService.getPodDiskReads(step));
    }

    @ApiOperation(value = "获取容器硬盘写入情况")
    @GetMapping("/podDiskWrites")
    public GenericsTableDataInfo<K8sPodContainerMetric> getPodDiskWrites(@RequestParam(value = "step", required = false) @ApiParam(value = "统计频率") Long step) {
        return new GenericsTableDataInfo<>(microStatusService.getPodDiskWrites(step));
    }

    @ApiOperation(value = "获取容器网络接收情况")
    @GetMapping("/podNetworkReception")
    public GenericsTableDataInfo<K8sPodContainerMetric> getPodNetworkReception(@RequestParam(value = "step", required = false) @ApiParam(value = "统计频率") Long step) {
        return new GenericsTableDataInfo<>(microStatusService.getPodNetworkReception(step));
    }

    @ApiOperation(value = "获取容器网络发送情况")
    @GetMapping("/podNetworkTransmission")
    public GenericsTableDataInfo<K8sPodContainerMetric> getPodNetworkTransmission(@RequestParam(value = "step", required = false) @ApiParam(value = "统计频率") Long step) {
        return new GenericsTableDataInfo<>(microStatusService.getPodNetworkTransmission(step));
    }
}
