package com.lanyuanxiaoyao.service.flink.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.lanyuanxiaoyao.service.configuration.entity.flink.*;
import com.lanyuanxiaoyao.service.flink.service.FlinkService;
import org.eclipse.collections.api.list.ImmutableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lanyuanxiaoyao
 * @date 2023-05-04
 */
@RestController
@RequestMapping("flink")
public class FlinkController {
    private static final Logger logger = LoggerFactory.getLogger(FlinkController.class);

    private final FlinkService flinkService;

    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    public FlinkController(FlinkService flinkService) {
        this.flinkService = flinkService;
    }

    @GetMapping("/overview")
    public FlinkOverview overview(@RequestParam("url") String url) throws JsonProcessingException {
        return flinkService.overview(url);
    }

    @GetMapping("/config")
    public FlinkConfig config(@RequestParam("url") String url) throws JsonProcessingException {
        return flinkService.config(url);
    }

    @GetMapping("/job_manager_config")
    public ImmutableList<FlinkKeyValue> jobManagerConfig(@RequestParam("url") String url) throws JsonProcessingException {
        return flinkService.jobManagerConfig(url);
    }

    @GetMapping("/vertex_overview")
    public FlinkVertexOverview vertexOverview(@RequestParam("url") String url) throws JsonProcessingException {
        return flinkService.vertexOverview(url);
    }

    @GetMapping("/vertex")
    public FlinkVertex vertex(@RequestParam("url") String url, @RequestParam("vertex_id") String vertexId) throws JsonProcessingException {
        return flinkService.vertex(url, vertexId);
    }

    @GetMapping("/vertex_config")
    public FlinkVertexConfig vertexConfig(@RequestParam("url") String url, @RequestParam("vertex_id") String vertexId) throws JsonProcessingException {
        return flinkService.vertexConfig(url, vertexId);
    }

    @GetMapping("/checkpoint_overview")
    public FlinkCheckpointOverview checkpointOverview(@RequestParam("url") String url, @RequestParam("vertex_id") String vertexId) throws JsonProcessingException {
        return flinkService.checkpointOverview(url, vertexId);
    }

    @GetMapping("/checkpoint")
    public FlinkCheckpoint checkpoint(@RequestParam("url") String url, @RequestParam("vertex_id") String vertexId, @RequestParam("checkpoint_id") Long checkpointId) throws JsonProcessingException {
        return flinkService.checkpoint(url, vertexId, checkpointId);
    }

    @GetMapping("/checkpoint_config")
    public FlinkCheckpointConfig checkpointConfig(@RequestParam("url") String url, @RequestParam("vertex_id") String vertexId) throws JsonProcessingException {
        return flinkService.checkpointConfig(url, vertexId);
    }

    @GetMapping("/task_manager_overview")
    public FlinkTaskManagerOverview taskManagerOverview(@RequestParam("url") String url) throws JsonProcessingException {
        return flinkService.taskManagerOverview(url);
    }

    @GetMapping("/task_manager")
    public FlinkTaskManager taskManager(@RequestParam("url") String url, @RequestParam("task_manager_id") String taskManagerId) throws JsonProcessingException {
        return flinkService.taskManager(url, taskManagerId);
    }
}
