"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.updatePortalOrgSettings = updatePortalOrgSettings;
const arcgis_rest_request_1 = require("@esri/arcgis-rest-request");
const util_1 = require("../../util");
/**
 * Function to update a user's org settings. Expects the user to be an org admin in the current org.
 * Currently only updates whether to show the informational banner.
 * @param settings
 */
async function updatePortalOrgSettings(settings, context) {
    // check that user is authed
    if (!context.currentUser) {
        throw new Error("User is not authenticated");
    }
    // check that user is org admin
    if (!context.isOrgAdmin) {
        throw new Error("User is not an org admin in the current org");
    }
    // grab and clone portalProperties
    const portalProperties = (0, util_1.cloneObject)(context.portal.portalProperties);
    // grab settings
    const { showInformationalBanner } = settings;
    // update infoBanner value in portalProperties
    portalProperties.hub.settings.informationalBanner = showInformationalBanner;
    // build the url
    const urlPath = `/sharing/rest/portals/self/update?f=json`;
    const url = `${context.portalUrl}${urlPath}`;
    // send the request to update
    return (0, arcgis_rest_request_1.request)(url, {
        httpMethod: "POST",
        params: {
            portalProperties: JSON.stringify(portalProperties),
            token: context.hubRequestOptions.authentication.token,
        },
    });
}
//# sourceMappingURL=updatePortalOrgSettings.js.map