package com.lanyuanxiaoyao.service.info.controller;

import com.lanyuanxiaoyao.service.common.entity.FlinkJob;
import com.lanyuanxiaoyao.service.info.service.FlinkJobService;
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;

/**
 * Flink Job
 *
 * @author lanyuanxiaoyao
 * @date 2024-01-03
 */
@RestController
@RequestMapping("/info")
public class FlinkJobController {
    private static final Logger logger = LoggerFactory.getLogger(FlinkJobController.class);

    private final FlinkJobService flinkJobService;

    public FlinkJobController(FlinkJobService flinkJobService) {
        this.flinkJobService = flinkJobService;
    }

    @GetMapping("/flink_job/list")
    public ImmutableList<FlinkJob> list() {
        return flinkJobService.flinkJobs();
    }

    @GetMapping("/flink_job/detail")
    public FlinkJob detail(@RequestParam("flink_job_id") Long flinkJobId) {
        return flinkJobService.flinkJob(flinkJobId);
    }

    @GetMapping("/flink_job/save")
    public void saveFlinkJob(
            @RequestParam("id") Long id,
            @RequestParam("name") String name,
            @RequestParam("run_mode") String runMode
    ) {
        flinkJobService.saveFlinkJob(id, name, runMode);
    }
}
