"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchSiteModel = fetchSiteModel;
const strip_protocol_1 = require("../urls/strip-protocol");
const is_guid_1 = require("../utils/is-guid");
const lookup_domain_1 = require("./domains/lookup-domain");
const get_site_by_id_1 = require("./get-site-by-id");
/**
 * Returns site model given various kinds of identifier
 *
 * @param identifier - a site item ID, site hostname, enterprise site slug, or full site URL
 * @param hubRequestOptions
 */
function fetchSiteModel(identifier, hubRequestOptions) {
    let prms;
    if ((0, is_guid_1.isGuid)(identifier)) {
        prms = (0, get_site_by_id_1.getSiteById)(identifier, hubRequestOptions);
    }
    else {
        let hostnameOrSlug = identifier;
        // get down the the hostname
        hostnameOrSlug = (0, strip_protocol_1.stripProtocol)(hostnameOrSlug);
        hostnameOrSlug = hostnameOrSlug.split("/")[0];
        prms = (0, lookup_domain_1.lookupDomain)(hostnameOrSlug, hubRequestOptions).then(({ siteId }) => (0, get_site_by_id_1.getSiteById)(siteId, hubRequestOptions));
    }
    return prms;
}
//# sourceMappingURL=fetchSiteModel.js.map