/**
 * @amigo-ai/platform-sdk
 *
 * Official TypeScript SDK for the Amigo Platform API.
 *
 * @example
 * ```typescript
 * import { AmigoClient } from '@amigo-ai/platform-sdk'
 *
 * const client = new AmigoClient({
 *   apiKey: 'your-api-key',
 *   workspaceId: 'your-workspace-id',
 * })
 *
 * const agents = await client.agents.list()
 * console.log(agents.items)
 * ```
 */
import { ConfigurationError } from './core/errors.js';
import { applyPlatformRequestOptions, createPlatformClient, } from './core/openapi-client.js';
import { mergeRequestOptions, } from './core/request-options.js';
import { WorkspacesResource } from './resources/workspaces.js';
import { ApiKeysResource } from './resources/api-keys.js';
import { AgentsResource } from './resources/agents.js';
import { SkillsResource } from './resources/skills.js';
import { ActionsResource } from './resources/actions.js';
import { OperatorsResource } from './resources/operators.js';
import { TriggersResource } from './resources/triggers.js';
import { ServicesResource } from './resources/services.js';
import { ContextGraphsResource } from './resources/context-graphs.js';
import { DataSourcesResource } from './resources/data-sources.js';
import { WorldResource } from './resources/world.js';
import { CallsResource } from './resources/calls.js';
import { PhoneNumbersResource } from './resources/phone-numbers.js';
import { IntegrationsResource } from './resources/integrations.js';
import { AnalyticsResource } from './resources/analytics.js';
import { SimulationsResource } from './resources/simulations.js';
import { MetricsResource } from './resources/metrics.js';
import { SettingsResource } from './resources/settings.js';
import { BillingResource } from './resources/billing.js';
import { MemoryResource } from './resources/memory.js';
import { PersonasResource } from './resources/personas.js';
import { ReviewQueueResource } from './resources/review-queue.js';
import { RecordingsResource } from './resources/recordings.js';
import { AuditResource } from './resources/audit.js';
import { WebhookDestinationsResource } from './resources/webhook-destinations.js';
import { SafetyResource } from './resources/safety.js';
import { ComplianceResource } from './resources/compliance.js';
import { FunctionsResource } from './resources/functions.js';
import { resolveScopedPlatformClient, scopePlatformClient } from './resources/base.js';
import { withResponse } from './core/utils.js';
export const DEFAULT_BASE_URL = 'https://api.platform.amigo.ai';
export class AmigoClient {
    workspaceId;
    baseUrl;
    workspaces;
    apiKeys;
    agents;
    /** @deprecated Use `actions` instead */
    skills;
    actions;
    operators;
    triggers;
    services;
    contextGraphs;
    dataSources;
    world;
    calls;
    phoneNumbers;
    integrations;
    analytics;
    simulations;
    metrics;
    settings;
    billing;
    memory;
    personas;
    reviewQueue;
    recordings;
    audit;
    webhookDestinations;
    safety;
    compliance;
    functions;
    /** @internal — exposed for path-level type inference in GET/POST/PUT/etc. */
    api;
    constructor(config) {
        if (!config.apiKey || typeof config.apiKey !== 'string') {
            throw new ConfigurationError('apiKey is required and must be a non-empty string');
        }
        if (!config.workspaceId || typeof config.workspaceId !== 'string') {
            throw new ConfigurationError('workspaceId is required and must be a non-empty string');
        }
        const baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, '');
        const client = createPlatformClient({
            apiKey: config.apiKey,
            baseUrl,
            retry: config.retry,
            maxRetries: config.maxRetries,
            timeout: config.timeout,
            headers: config.headers,
            hooks: config.hooks,
            fetch: config.fetch,
        });
        AmigoClient.hydrate(this, client, config.workspaceId, baseUrl);
    }
    withOptions(options) {
        return AmigoClient.fromPlatformClient(scopePlatformClient(this.api, options), this.workspaceId, this.baseUrl);
    }
    async GET(path, ...[init]) {
        return withResponse(await this.resolveApiRequest(path, 'GET', init));
    }
    async POST(path, ...[init]) {
        return withResponse(await this.resolveApiRequest(path, 'POST', init));
    }
    async PUT(path, ...[init]) {
        return withResponse(await this.resolveApiRequest(path, 'PUT', init));
    }
    async PATCH(path, ...[init]) {
        return withResponse(await this.resolveApiRequest(path, 'PATCH', init));
    }
    async DELETE(path, ...[init]) {
        return withResponse(await this.resolveApiRequest(path, 'DELETE', init));
    }
    async HEAD(path, ...[init]) {
        return withResponse(await this.resolveApiRequest(path, 'HEAD', init), {
            allowEmptyBody: true,
        });
    }
    async OPTIONS(path, ...[init]) {
        return withResponse(await this.resolveApiRequest(path, 'OPTIONS', init), {
            allowEmptyBody: true,
        });
    }
    static fromPlatformClient(client, workspaceId, baseUrl) {
        const instance = Object.create(AmigoClient.prototype);
        AmigoClient.hydrate(instance, client, workspaceId, baseUrl);
        return instance;
    }
    static hydrate(target, client, workspaceId, baseUrl) {
        const mutable = target;
        mutable.workspaceId = workspaceId;
        mutable.baseUrl = baseUrl;
        target.api = client;
        mutable.workspaces = new WorkspacesResource(client, workspaceId);
        mutable.apiKeys = new ApiKeysResource(client, workspaceId);
        mutable.agents = new AgentsResource(client, workspaceId);
        mutable.skills = new SkillsResource(client, workspaceId);
        mutable.actions = new ActionsResource(client, workspaceId);
        mutable.operators = new OperatorsResource(client, workspaceId);
        mutable.triggers = new TriggersResource(client, workspaceId);
        mutable.services = new ServicesResource(client, workspaceId);
        mutable.contextGraphs = new ContextGraphsResource(client, workspaceId);
        mutable.dataSources = new DataSourcesResource(client, workspaceId);
        mutable.world = new WorldResource(client, workspaceId);
        mutable.calls = new CallsResource(client, workspaceId);
        mutable.phoneNumbers = new PhoneNumbersResource(client, workspaceId);
        mutable.integrations = new IntegrationsResource(client, workspaceId);
        mutable.analytics = new AnalyticsResource(client, workspaceId);
        mutable.simulations = new SimulationsResource(client, workspaceId);
        mutable.metrics = new MetricsResource(client, workspaceId);
        mutable.settings = new SettingsResource(client, workspaceId);
        mutable.billing = new BillingResource(client, workspaceId);
        mutable.memory = new MemoryResource(client, workspaceId);
        mutable.personas = new PersonasResource(client, workspaceId);
        mutable.reviewQueue = new ReviewQueueResource(client, workspaceId);
        mutable.recordings = new RecordingsResource(client, workspaceId);
        mutable.audit = new AuditResource(client, workspaceId);
        mutable.webhookDestinations = new WebhookDestinationsResource(client, workspaceId);
        mutable.safety = new SafetyResource(client, workspaceId);
        mutable.compliance = new ComplianceResource(client, workspaceId);
        mutable.functions = new FunctionsResource(client, workspaceId);
    }
    async resolveApiRequest(path, method, init) {
        const { baseClient, options } = resolveScopedPlatformClient(this.api);
        const mergedInit = mergeRequestOptions(options, withWorkspaceId(path, init, this.workspaceId));
        const requestInit = applyPlatformRequestOptions(baseClient, mergedInit);
        switch (method) {
            case 'GET':
                return await baseClient.GET(path, requestInit);
            case 'POST':
                return await baseClient.POST(path, requestInit);
            case 'PUT':
                return await baseClient.PUT(path, requestInit);
            case 'PATCH':
                return await baseClient.PATCH(path, requestInit);
            case 'DELETE':
                return await baseClient.DELETE(path, requestInit);
            case 'HEAD':
                return await baseClient.HEAD(path, requestInit);
            case 'OPTIONS':
                return await baseClient.OPTIONS(path, requestInit);
        }
    }
}
export { AmigoError, BadRequestError, AuthenticationError, PermissionError, NotFoundError, ConflictError, ValidationError, RateLimitError, ServerError, ServiceUnavailableError, NetworkError, RequestTimeoutError, ParseError, ConfigurationError, isAmigoError, isNotFoundError, isRateLimitError, isAuthenticationError, isRequestTimeoutError, } from './core/errors.js';
export { workspaceId, apiKeyId, agentId, personaId, skillId, actionId, serviceId, contextGraphId, callId, phoneNumberId, integrationId, entityId, eventId, simulationRunId, simulationSessionId, functionId, dataSourceId, } from './core/branded-types.js';
export { paginate } from './core/utils.js';
export { buildLastResponse, extractRequestId } from './core/utils.js';
export { parseRateLimitHeaders } from './core/rate-limit.js';
export { verifyWebhookSignature, parseWebhookEvent, WebhookVerificationError, } from './core/webhooks.js';
function withWorkspaceId(path, init, workspaceId) {
    if (!path.includes('{workspace_id}')) {
        return (init ?? {});
    }
    const current = (init ?? {});
    return {
        ...current,
        params: {
            ...(current.params ?? {}),
            path: {
                ...(current.params?.path ?? {}),
                workspace_id: workspaceId,
            },
        },
    };
}
//# sourceMappingURL=index.js.map