"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getModelBySlug = getModelBySlug;
const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
const slugs_1 = require("../items/slugs");
/**
 * Get a model by it's slug
 *
 * This uses the [Filter](https://developers.arcgis.com/rest/users-groups-and-items/search-reference.htm) option of the
 * to search for an item that has a typekeyword of `slug|{slug-value}`
 *
 * This is useful for applications that want to use human-readable urls instead
 * of using item ids.
 *
 * @param slug
 * @param requestOptions
 * @returns
 */
function getModelBySlug(slug, requestOptions) {
    return (0, slugs_1.getItemBySlug)(slug, requestOptions)
        .then((item) => {
        const prms = [Promise.resolve(item)];
        if (item) {
            prms.push((0, arcgis_rest_portal_1.getItemData)(item.id, requestOptions));
        }
        else {
            prms.push(Promise.resolve(null));
        }
        return Promise.all(prms);
    })
        .then((result) => {
        if (result[0]) {
            return {
                item: result[0],
                data: result[1],
            };
        }
        else {
            return null;
        }
    });
}
//# sourceMappingURL=getModelBySlug.js.map