/*!
 * Copyright (C) Microsoft Corporation. All rights reserved.
 */
import { getPlayerServiceConfig } from '../initializePlayerServices.js';
import { getBapRPAuthResource, getPowerPlatformApiEnvironmentConfig, } from '../PowerPlatformApiUtils.js';
export async function getFlowMetadataAsync(flowId, logger) {
    const scenario = logger?.trackScenario('GetFlowMetadataAsync', { flowId });
    let additionalScenarioData = {};
    try {
        const { endpoint, authResource } = getPowerPlatformApiEnvironmentConfig(getBapRPAuthResource());
        const { httpClient } = getPlayerServiceConfig();
        const url = `https://${endpoint}/powerautomate/flows/${flowId}?api-version=1&$expand=properties,properties.connectionreferences.apidefinition`;
        const response = await httpClient.get(url, {
            authResource,
        });
        additionalScenarioData = { url, authResource, status: response.status };
        if (response.status === 200) {
            scenario?.complete(additionalScenarioData);
            return response.data;
        }
        else {
            scenario?.completeWithError(additionalScenarioData);
            throw new Error(`Unexpected response status ${response.status} from ${url}`);
        }
    }
    catch (error) {
        scenario?.failure({ error, ...additionalScenarioData });
        throw error;
    }
}
export async function getFlowSwaggerAsync(flowId, logger) {
    const scenario = logger?.trackScenario('GetFlowSwaggerAsync', { flowId });
    let additionalScenarioData = {};
    try {
        const { endpoint, authResource } = getPowerPlatformApiEnvironmentConfig(getBapRPAuthResource());
        const { httpClient } = getPlayerServiceConfig();
        const url = `https://${endpoint}/powerautomate/flows/${flowId}/listSwagger?api-version=2024-10-01`;
        const response = await httpClient.post(url, {
            authResource,
        });
        additionalScenarioData = { url, authResource, status: response.status };
        if (response.status === 200) {
            scenario?.complete(additionalScenarioData);
            return response.data;
        }
        else {
            scenario?.completeWithError(additionalScenarioData);
            throw new Error(`Unexpected response status ${response.status} from ${url}`);
        }
    }
    catch (error) {
        scenario?.failure({ error, ...additionalScenarioData });
        throw error;
    }
}
//# sourceMappingURL=PowerAutomateRpService.js.map