/*!
 * Copyright (C) Microsoft Corporation. All rights reserved.
 */
import { createPowerPlatformApiEnvironmentEndpoint } from '../ServiceEndpoints.js';
const enc = encodeURIComponent;
/** Typed API client for Power Platform connector/connection endpoints. No business logic. */
export class ConnectorsApi {
    httpClient;
    env;
    constructor(httpClient, clusterCategory, environmentName) {
        this.httpClient = httpClient;
        this.env = httpClient.registerEndpoint('connectors:env', createPowerPlatformApiEnvironmentEndpoint(environmentName, clusterCategory));
    }
    /** Fetch all connections in the environment (with expanded API metadata). */
    async getConnections() {
        const response = await this.httpClient.get(`${this.env}/connectivity/connections?api-version=1&%24expand=api`);
        return response.data.value;
    }
    /** Get a connection by name. */
    async getConnection(connectionName) {
        const response = await this.httpClient.get(`${this.env}/providers/Microsoft.PowerApps/connections/${enc(connectionName)}`);
        return response.data;
    }
    /** Get a connection by its ID. */
    async getConnectionById(connectionId) {
        const response = await this.httpClient.get(`${this.env}/providers/Microsoft.PowerApps/connections/${enc(connectionId)}`);
        return response.data;
    }
    /** Test a connection via the wrapper API. */
    async testConnection(connectionName) {
        await this.httpClient.post(`${this.env}/providers/Microsoft.PowerApps/connections/${enc(connectionName)}/test`);
    }
    /** Save user consents for an app. */
    async saveUserConsents(appName, consents) {
        await this.httpClient.post(`${this.env}/providers/Microsoft.PowerApps/apps/${enc(appName)}/saveUserConsents`, { consents });
    }
    /** Request SSO consent for a connection. */
    async requestConnectionConsent(connectionName, body) {
        await this.httpClient.post(`${this.env}/providers/Microsoft.PowerApps/connections/${enc(connectionName)}/consent`, body);
    }
    /** Save a connection usage (bind a connection to an app reference). */
    async saveConnectionUsage(apiShortName, connectionName, environmentName, body) {
        await this.httpClient.post(`${this.env}/powerapps/apis/${enc(apiShortName)}/connections/${enc(connectionName)}/usages?api-version=1&%24filter=environment+eq+%27${enc(environmentName)}%27`, { properties: body });
    }
    /** Create or update a composite connection. */
    async createCompositeConnection(apiId, body) {
        const response = await this.httpClient.post(`${this.env}/providers/Microsoft.PowerApps/apis/${enc(apiId)}/connections`, body);
        return response.data;
    }
}
//# sourceMappingURL=ConnectorsApi.js.map