package com.lanyuanxiaoyao.service.yarn.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnApplication;
import com.lanyuanxiaoyao.service.yarn.service.JobService;
import org.eclipse.collections.api.list.ImmutableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
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;

/**
 * Job
 *
 * @author lanyuanxiaoyao
 * @date 2023-04-23
 */
@RestController
@RequestMapping("job")
public class JobController {
    private static final Logger logger = LoggerFactory.getLogger(JobController.class);

    private final JobService jobService;

    public JobController(@Qualifier("JobService") JobService jobService) {
        this.jobService = jobService;
    }

    @GetMapping("list")
    public ImmutableList<YarnApplication> list(@RequestParam("cluster") String cluster) throws JsonProcessingException {
        return jobService.list(cluster);
    }

    @GetMapping("list_running")
    public ImmutableList<YarnApplication> listRunning(@RequestParam("cluster") String cluster) throws JsonProcessingException {
        return jobService.listRunning(cluster);
    }

    @GetMapping("list_not_running")
    public ImmutableList<YarnApplication> listNotRunning(@RequestParam("cluster") String cluster) throws JsonProcessingException {
        return jobService.listNotRunning(cluster);
    }

    @GetMapping("list_equals")
    public ImmutableList<YarnApplication> listEquals(@RequestParam("cluster") String cluster, @RequestParam("name") String name) throws JsonProcessingException {
        return jobService.listEquals(cluster, name);
    }

    @GetMapping("list_running_equals")
    public ImmutableList<YarnApplication> listRunningEquals(@RequestParam("cluster") String cluster, @RequestParam("name") String name) throws JsonProcessingException {
        return jobService.listRunningEquals(cluster, name);
    }

    @GetMapping("list_not_running_equals")
    public ImmutableList<YarnApplication> listNotRunningEquals(@RequestParam("cluster") String cluster, @RequestParam("name") String name) throws JsonProcessingException {
        return jobService.listNotRunningEquals(cluster, name);
    }

    @GetMapping("list_like")
    public ImmutableList<YarnApplication> listLike(@RequestParam("cluster") String cluster, @RequestParam("text") String text) throws JsonProcessingException {
        return jobService.listLike(cluster, text);
    }

    @GetMapping("list_running_like")
    public ImmutableList<YarnApplication> listRunningLike(@RequestParam("cluster") String cluster, @RequestParam("text") String text) throws JsonProcessingException {
        return jobService.listRunningLike(cluster, text);
    }

    @GetMapping("list_not_running_like")
    public ImmutableList<YarnApplication> listNotRunningLike(@RequestParam("cluster") String cluster, @RequestParam("text") String text) throws JsonProcessingException {
        return jobService.listNotRunningLike(cluster, text);
    }

    @GetMapping("detail")
    public YarnApplication detail(@RequestParam("cluster") String cluster, @RequestParam("application_id") String applicationId) throws Exception {
        return jobService.detail(cluster, applicationId);
    }
}
