import { z } from 'zod';
import { APIResponseSchema } from "../api.js";
import { ConsumerSchema } from "./types.js";
import { buildQueueHeaders, QueueError, queueApiPath, withQueueErrorHandling } from "./util.js";
import { validateQueueName } from "./validation.js";
export const ConsumersListResponseSchema = APIResponseSchema(z.object({
    consumers: z.array(ConsumerSchema),
    total: z.number(),
}));
/**
 * List consumers for a queue.
 *
 * Returns active WebSocket consumers and recently disconnected durable consumers.
 *
 * @param client - The API client instance
 * @param queueName - The name of the queue
 * @param options - Optional API options (e.g., orgId for CLI-authenticated requests)
 * @returns Array of consumers
 * @throws {QueueNotFoundError} If the queue does not exist
 * @throws {QueueError} If the API request fails
 *
 * @example
 * ```typescript
 * const consumers = await listConsumers(client, 'order-processing');
 * for (const consumer of consumers) {
 *   const status = consumer.disconnected_at ? 'disconnected' : 'connected';
 *   console.log(`Consumer ${consumer.id}: ${status} (durable: ${consumer.durable})`);
 * }
 * ```
 */
export async function listConsumers(client, queueName, options) {
    validateQueueName(queueName);
    const url = queueApiPath('consumers/list', queueName);
    const resp = await withQueueErrorHandling(() => client.get(url, ConsumersListResponseSchema, undefined, buildQueueHeaders(options?.orgId)), { queueName });
    if (resp.success) {
        return resp.data.consumers;
    }
    throw new QueueError({
        queueName,
        message: resp.message || 'Failed to list consumers',
    });
}
//# sourceMappingURL=consumers.js.map