import httpClient from '@/utils/http';

import { MessageQueueMessageVO, MessageQueueQueueStatsVO } from './data-contracts';
export default {
  /**
   * @description 获取所有可用的消息队列
   */
  queuesList: () => {
    return httpClient.get<Record<string, any>>(`/queues`);
  },
  /**
   * @description 创建新的消息队列
   */
  queuesCreate: (queueName: string) => {
    return httpClient.post<Record<string, any>>(`/queues/${queueName}`);
  },
  /**
   * @description 删除指定的消息队列
   */
  queuesDelete: (queueName: string) => {
    return httpClient.delete<Record<string, any>>(`/queues/${queueName}`);
  },
  /**
   * @description 确认消息处理完成
   */
  messagesAckCreate: (queueName: string, messageId: string) => {
    return httpClient.post<Record<string, any>>(`/queues/${queueName}/messages/${messageId}/ack`);
  },
  /**
   * @description 拒绝消息处理
   */
  messagesNackCreate: (queueName: string, messageId: string, requeue: boolean) => {
    return httpClient.post<Record<string, any>>(`/queues/${queueName}/messages/${messageId}/nack`, {
      params: requeue
    });
  },
  /**
   * @description 获取指定队列的统计信息
   */
  statsDetail: (queueName: string) => {
    return httpClient.get<MessageQueueQueueStatsVO>(`/queues/${queueName}/stats`);
  },
  /**
   * @description 批量向指定队列的主题发布消息
   */
  topicsBatchPublishCreate: (queueName: string, topic: string, messages: Record<string, any>[]) => {
    return httpClient.post<Record<string, any>>(
      `/queues/${queueName}/topics/${topic}/batch-publish`,
      { params: messages }
    );
  },
  /**
   * @description 从指定队列的主题获取消息
   */
  topicsMessageDetail: (queueName: string, topic: string) => {
    return httpClient.get<MessageQueueMessageVO>(`/queues/${queueName}/topics/${topic}/message`);
  },
  /**
   * @description 向指定队列的主题发布消息
   */
  topicsPublishCreate: (queueName: string, topic: string, message: Record<string, any>) => {
    return httpClient.post<Record<string, any>>(`/queues/${queueName}/topics/${topic}/publish`, {
      params: message
    });
  }
};
