"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerSiteAsApplication = registerSiteAsApplication;
const registerBrowserApp_1 = require("../items/registerBrowserApp");
const get_prop_1 = require("../objects/get-prop");
const _get_http_and_https_uris_1 = require("../urls/_get-http-and-https-uris");
/**
 * @private
 * @internal
 * As of May 2023, Hub Site Application registration must be done via HMAC signed request
 * which is handled by the Hub Domain Service. This file is left here for reference.
 * Register the Site item as an application so we can oauth against it
 * @param {string} siteId Item Id of the site
 * @param {Array} uris Arrayf valid uris for the site
 * @param {IHubRequestOptions} hubRequestOptions
 */
function registerSiteAsApplication(model, hubRequestOptions) {
    // PORTAL-ENV: we can't register sites as `arcgisonline` because it will bust sign in on the portal
    if (hubRequestOptions.isPortal)
        return Promise.resolve({});
    const uris = [model.data.values.defaultHostname];
    if ((0, get_prop_1.getProp)(model, "data.values.customHostname")) {
        uris.push(model.data.values.customHostname);
    }
    // get both the http and https versions of the urls, just to cover all the bases
    const redirectUris = uris.reduce((acc, uri) => {
        return acc.concat((0, _get_http_and_https_uris_1._getHttpAndHttpsUris)(uri));
    }, []);
    return (0, registerBrowserApp_1.registerBrowserApp)(model.item.id, redirectUris, hubRequestOptions);
}
//# sourceMappingURL=registerSiteAsApplication.js.map