export * from "./service.js";
import { QueueStorageService, } from "./service.js";
import { StructuredError } from '@agentuity/adapter';
import { getServiceUrls } from '@agentuity/config';
import { createServiceAdapter, isLogger, resolveApiKey, resolveRegion, resolveServiceUrl, } from '@agentuity/client';
import { z, ZodError } from 'zod';
const QueueClientValidationError = StructuredError('QueueClientValidationError')();
export const QueueClientOptionsSchema = z.object({
    apiKey: z.string().optional().describe('API key for authentication'),
    url: z.string().optional().describe('Base URL for the Queue API'),
    orgId: z.string().optional().describe('Organization ID for multi-tenant operations'),
    logger: z.custom(isLogger).optional().describe('Custom logger instance'),
});
export class QueueClient {
    #service;
    constructor(options = {}) {
        let validatedOptions;
        try {
            validatedOptions = QueueClientOptionsSchema.parse(options);
        }
        catch (err) {
            if (err instanceof ZodError) {
                throw new QueueClientValidationError({
                    message: 'Invalid QueueClient options',
                    schema: 'QueueClientOptionsSchema',
                    issues: err.issues.map((i) => ({
                        path: i.path.join('.'),
                        message: i.message,
                    })),
                    cause: err,
                });
            }
            throw err;
        }
        const apiKey = resolveApiKey(validatedOptions.apiKey);
        const serviceUrls = getServiceUrls(resolveRegion());
        const url = resolveServiceUrl({
            url: validatedOptions.url,
            envKey: 'AGENTUITY_QUEUE_URL',
            fallback: serviceUrls.catalyst,
        });
        const { adapter } = createServiceAdapter({
            apiKey,
            orgId: validatedOptions.orgId,
            logger: validatedOptions.logger,
        });
        this.#service = new QueueStorageService(url, adapter);
    }
    async publish(queueName, payload, params) {
        return this.#service.publish(queueName, payload, params);
    }
    async createQueue(queueName, params) {
        return this.#service.createQueue(queueName, params);
    }
    async deleteQueue(queueName) {
        return this.#service.deleteQueue(queueName);
    }
}
//# sourceMappingURL=index.js.map