"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeDomainByHostname = removeDomainByHostname;
// These will be spied on in tests
const lookup_domain_1 = require("./lookup-domain");
const remove_domain_1 = require("./remove-domain");
const get_prop_1 = require("../../objects/get-prop");
/**
 * Remove an entry from the domain service, based on a hostname
 *
 * Callers must ensure the user is a member of the org that
 * owns the domain entry else the call will fail.
 * @param hostname
 * @param hubRequestOptions
 */
async function removeDomainByHostname(hostname, hubRequestOptions) {
    if (hubRequestOptions.isPortal) {
        throw new Error(`removeDomainByHostname is not available in ArcGIS Enterprise. Instead, edit the hubdomain typekeyword on the item`);
    }
    try {
        const domainEntry = await (0, lookup_domain_1.lookupDomain)(hostname, hubRequestOptions);
        // Could consider doing a check here to verify that current user
        // is member of the org owning the domain record, but api will
        // enforce this.
        const id = (0, get_prop_1.getProp)(domainEntry, "id");
        if (id) {
            await (0, remove_domain_1.removeDomain)(id, hubRequestOptions);
        }
    }
    catch (ex) {
        throw new Error(`Error removing domain entry for ${hostname}: ${ex.message}`);
    }
}
//# sourceMappingURL=removeDomainByHostname.js.map