package com.lanyuanxiaoyao.service.info.controller;

import cn.hutool.core.util.ObjectUtil;
import com.lanyuanxiaoyao.service.configuration.entity.PageResponse;
import com.lanyuanxiaoyao.service.configuration.entity.info.CompactionMetrics;
import com.lanyuanxiaoyao.service.info.service.CompactionService;
import java.util.List;
import org.eclipse.collections.api.factory.Lists;
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;

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

    private final CompactionService compactionService;

    public CompactionController(CompactionService compactionService) {
        this.compactionService = compactionService;
    }

    @GetMapping("/compaction_metrics")
    public PageResponse<CompactionMetrics> metrics(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "count", defaultValue = "10") Integer count,
            @RequestParam(value = "flink_job_id") Long flinkJobId,
            @RequestParam(value = "alias") String alias,
            @RequestParam(value = "order", required = false) String order,
            @RequestParam(value = "direction", required = false) String direction,
            @RequestParam(value = "filter_completes", required = false) List<Boolean> filterCompletes
    ) {
        return compactionService.findAllCompactionMetrics(
                page,
                count,
                flinkJobId,
                alias,
                order,
                direction,
                ObjectUtil.isNull(filterCompletes) ? Lists.immutable.empty() : Lists.immutable.ofAll(filterCompletes)
        );
    }
}
