"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolvePortalValues = resolvePortalValues;
const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
const set_prop_1 = require("../../objects/set-prop");
const get_prop_1 = require("../../objects/get-prop");
const memoize_1 = require("../memoize");
/**
 * @internal
 * Resolve a set of dynamic values by extracting properties
 * from the current user's portal/self
 * @param valueDef Portal Query Definition that wil be resolved using properties from the current user's portal/self
 * @param context ArcGIS context of the current user.
 * @returns
 */
async function resolvePortalValues(valueDef, context) {
    const result = {};
    const memoizedPortalSelf = (0, memoize_1.memoize)(arcgis_rest_portal_1.getSelf);
    // TODO: This could use the context.portal values to skip even a single request
    // get the portalSelf via memoized function
    const portal = await memoizedPortalSelf(context.requestOptions.authentication);
    // get the value from the portal and attach into the result
    const value = (0, get_prop_1.getProp)(portal, valueDef.sourcePath);
    (0, set_prop_1.setProp)(valueDef.outPath, value, result);
    return result;
}
//# sourceMappingURL=resolvePortalValues.js.map