package org.dromara.ai.controller.app;

import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.ai.queue.TaskQueueService;
import org.dromara.common.core.domain.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 队列指标控制器
 * 提供任务队列的监控指标查询接口
 *
 * @author pengles
 */
@Slf4j
@RestController
@RequestMapping("/ai/queue")
@RequiredArgsConstructor
public class QueueMetricsController {
    
    private final TaskQueueService queueService;

    /**
     * 获取队列指标
     *
     * @return 队列指标信息
     */
    @GetMapping("/metrics")
    @Operation(summary = "队列指标", description = "获取任务队列的实时监控指标，包括队列深度、处理速率等")
    public R<Map<String, Object>> metrics() {
        try {
            Map<String, Object> metrics = queueService.metrics();
            log.debug("获取队列指标成功");
            return R.ok(metrics);
        } catch (Exception e) {
            log.error("获取队列指标失败", e);
            return R.fail("获取队列指标失败: " + e.getMessage());
        }
    }
}
