/*!
 * Copyright (C) Microsoft Corporation. All rights reserved.
 */
import { getPlayerServiceConfig } from '../initializePlayerServices.js';
import { getPowerPlatformApiEnvironmentConfig } from '../PowerPlatformApiUtils.js';
export async function listAppsAsync() {
    const { httpClient } = getPlayerServiceConfig();
    const { endpoint, authResource } = getPowerPlatformApiEnvironmentConfig();
    const url = `https://${endpoint}/powerapps/apps?api-version=1`;
    const response = await httpClient.get(url, {
        authResource,
    });
    return response.data.value;
}
export async function getEnvironmentByName(environmentName) {
    const { httpClient, apiVersions } = getPlayerServiceConfig();
    const { endpoint, authResource } = getPowerPlatformApiEnvironmentConfig();
    const url = `https://${endpoint}/powerapps/environment?api-version=${apiVersions.environment}&$filter=name eq '${environmentName}'`;
    const response = await httpClient.get(url, {
        authResource,
    });
    return response.data;
}
export async function createApp(app) {
    const { httpClient } = getPlayerServiceConfig();
    const { endpoint, authResource } = getPowerPlatformApiEnvironmentConfig();
    const url = `https://${endpoint}/powerapps/apps?api-version=1`;
    const response = await httpClient.post(url, {
        authResource,
        body: app,
    });
    return response.data;
}
export async function saveApp(appNameOrLogicalName, app) {
    const { httpClient } = getPlayerServiceConfig();
    const { endpoint, authResource } = getPowerPlatformApiEnvironmentConfig();
    const url = `https://${endpoint}/powerapps/apps/${appNameOrLogicalName}?api-version=1`;
    const result = await httpClient.put(url, {
        authResource,
        body: app,
    });
    return result.data;
}
export async function publishApp(appNameOrLogicalName) {
    const { httpClient } = getPlayerServiceConfig();
    const { endpoint, authResource } = getPowerPlatformApiEnvironmentConfig();
    const url = `https://${endpoint}/powerapps/apps/${appNameOrLogicalName}/publish?api-version=1`;
    await httpClient.post(url, {
        authResource,
    });
}
export async function generateResourceStorage() {
    const { httpClient } = getPlayerServiceConfig();
    const { endpoint, authResource } = getPowerPlatformApiEnvironmentConfig();
    const url = `https://${endpoint}/powerapps/generateResourceStorage?api-version=1`;
    const result = await httpClient.post(url, {
        authResource,
    });
    return result.data.sharedAccessSignature;
}
export async function startSession(appNameOrLogicalName) {
    const { httpClient } = getPlayerServiceConfig();
    const { endpoint, authResource } = getPowerPlatformApiEnvironmentConfig();
    const url = `https://${endpoint}/powerapps/apps/${appNameOrLogicalName}/startSession?forceStartNewSession=true&api-version=1`;
    const result = await httpClient.post(url, {
        authResource,
        body: {
            sessionType: 'Writer',
        },
    });
    return result.data;
}
export async function endSession(appNameOrLogicalName, sessionId) {
    const { httpClient } = getPlayerServiceConfig();
    const { endpoint, authResource } = getPowerPlatformApiEnvironmentConfig();
    const url = `https://${endpoint}/powerapps/apps/${appNameOrLogicalName}/sessions/${sessionId}/endSession?api-version=1`;
    await httpClient.post(url, {
        authResource,
    });
}
export async function makeAppSolutionAware(appNameOrLogicalName, solutionId) {
    const { httpClient } = getPlayerServiceConfig();
    const { endpoint, authResource } = getPowerPlatformApiEnvironmentConfig();
    const url = `https://${endpoint}/powerapps/apps/${appNameOrLogicalName}/makeSolutionAware?api-version=1`;
    await httpClient.post(url, {
        authResource,
        body: {
            solutionId,
        },
    });
}
//# sourceMappingURL=PowerAppsRpService.js.map