import { WorkspaceScopedResource, extractData } from './base.js';
/**
 * Manage external integrations that can own constrained client credentials for
 * customer backends.
 */
export class ExternalIntegrationsResource extends WorkspaceScopedResource {
    /** List external integrations in the workspace. */
    async list(params) {
        return extractData(await this.client.GET('/v1/{workspace_id}/external-integrations', {
            params: { path: { workspace_id: this.workspaceId }, query: params },
        }));
    }
    listAutoPaging(params) {
        return this.iteratePaginatedList((pageParams) => this.list(pageParams), params);
    }
    /** Register a customer/backend integration record. */
    async create(body) {
        return extractData(await this.client.POST('/v1/{workspace_id}/external-integrations', {
            params: { path: { workspace_id: this.workspaceId } },
            body,
        }));
    }
    /** Get one external integration. */
    async get(integrationId) {
        return extractData(await this.client.GET('/v1/{workspace_id}/external-integrations/{integration_id}', {
            params: { path: { workspace_id: this.workspaceId, integration_id: integrationId } },
        }));
    }
    /** Update external integration metadata. */
    async update(integrationId, body) {
        return extractData(await this.client.PATCH('/v1/{workspace_id}/external-integrations/{integration_id}', {
            params: { path: { workspace_id: this.workspaceId, integration_id: integrationId } },
            body,
        }));
    }
    /** Delete an external integration and revoke its active credentials. */
    async delete(integrationId) {
        await this.client.DELETE('/v1/{workspace_id}/external-integrations/{integration_id}', {
            params: { path: { workspace_id: this.workspaceId, integration_id: integrationId } },
        });
    }
    /** List credentials for an external integration. Plaintext secrets are never returned here. */
    async listCredentials(integrationId) {
        return extractData(await this.client.GET('/v1/{workspace_id}/external-integrations/{integration_id}/credentials', {
            params: { path: { workspace_id: this.workspaceId, integration_id: integrationId } },
        }));
    }
    /** Create a credential and return its one-time plaintext client secret. */
    async createCredential(integrationId, body) {
        return extractData(await this.client.POST('/v1/{workspace_id}/external-integrations/{integration_id}/credentials', {
            params: { path: { workspace_id: this.workspaceId, integration_id: integrationId } },
            body,
        }));
    }
    /** Revoke one external integration credential. */
    async revokeCredential(integrationId, credentialId) {
        await this.client.DELETE('/v1/{workspace_id}/external-integrations/{integration_id}/credentials/{credential_id}', {
            params: {
                path: {
                    workspace_id: this.workspaceId,
                    integration_id: integrationId,
                    credential_id: credentialId,
                },
            },
        });
    }
    /** Rotate a credential and return the replacement one-time plaintext client secret. */
    async rotateCredential(integrationId, credentialId) {
        return extractData(await this.client.POST('/v1/{workspace_id}/external-integrations/{integration_id}/credentials/{credential_id}/rotate', {
            params: {
                path: {
                    workspace_id: this.workspaceId,
                    integration_id: integrationId,
                    credential_id: credentialId,
                },
            },
        }));
    }
}
//# sourceMappingURL=external-integrations.js.map