package com.lanyuanxiaoyao.service.info.controller;

import com.lanyuanxiaoyao.service.configuration.entity.PageResponse;
import com.lanyuanxiaoyao.service.configuration.entity.info.JobIdAndAlias;
import com.lanyuanxiaoyao.service.configuration.entity.info.VersionUpdated;
import com.lanyuanxiaoyao.service.info.service.VersionService;
import java.util.List;
import org.eclipse.collections.api.factory.Lists;
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;

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

    private final VersionService versionService;

    public VersionController(VersionService versionService) {
        this.versionService = versionService;
    }

    @GetMapping("/non_updated_version_tables")
    public ImmutableList<String> nonUpdatedVersionTables() {
        return versionService.nonUpdatedVersionTables();
    }

    @GetMapping("/updated_version_tables")
    public ImmutableList<String> updatedVersionTables() {
        return versionService.updatedVersionTables();
    }

    @GetMapping("/version_tables")
    public PageResponse<VersionUpdated> list(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "count", defaultValue = "10") Integer count,
            @RequestParam(value = "version", required = false) String version,
            @RequestParam(value = "flink_job_id", required = false) Long flinkJobId,
            @RequestParam(value = "alias", required = false) String alias,
            @RequestParam(value = "order", required = false) String order,
            @RequestParam(value = "direction", required = false) String direction,
            @RequestParam(value = "filter_schedules", required = false) List<Boolean> filterSchedules
    ) {
        return versionService.findAllVersionTables(
                page,
                count,
                version,
                flinkJobId,
                alias,
                order,
                direction,
                Lists.immutable.ofAll(filterSchedules)
        );
    }

    @GetMapping("/un_scheduled_normal_table")
    public ImmutableList<JobIdAndAlias> unScheduledNormalTable(@RequestParam("version") String version) {
        return versionService.unScheduledNormalTable(version);
    }

    @GetMapping("/un_scheduled_normal_table_count")
    public Long unScheduledNormalTableCount(@RequestParam("version") String version) {
        return versionService.unScheduledNormalTableCount(version);
    }

    @GetMapping("/un_scheduled_focus_table")
    public ImmutableList<JobIdAndAlias> unScheduledFocusTable(@RequestParam("version") String version) {
        return versionService.unScheduledFocusTable(version);
    }

    @GetMapping("/un_scheduled_focus_table_count")
    public Long unScheduledFocusTableCount(@RequestParam("version") String version) {
        return versionService.unScheduledFocusTableCount(version);
    }

    @GetMapping("/un_receive_version_normal_table")
    public ImmutableList<JobIdAndAlias> unReceiveVersionNormalTable(@RequestParam("version") String version) {
        return versionService.unReceiveVersionNormalTable(version);
    }

    @GetMapping("/un_receive_version_normal_table_count")
    public Long unReceiveVersionNormalTableCount(@RequestParam("version") String version) {
        return versionService.unReceiveVersionNormalTableCount(version);
    }

    @GetMapping("/un_receive_version_focus_table")
    public ImmutableList<JobIdAndAlias> unReceiveVersionFocusTable(@RequestParam("version") String version) {
        return versionService.unReceiveVersionFocusTable(version);
    }

    @GetMapping("/un_receive_version_focus_table_count")
    public Long unReceiveVersionFocusTableCount(@RequestParam("version") String version) {
        return versionService.unReceiveVersionFocusTableCount(version);
    }
}
