"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "RandomEntityFetcher", {
    enumerable: true,
    get: function() {
        return RandomEntityFetcher;
    }
});
function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
const CACHEABLE_ENTITIES = new Set([
    'location',
    'locationGroup',
    'department',
    'facility'
]);
let RandomEntityFetcher = class RandomEntityFetcher {
    async getRandom(entity) {
        if (CACHEABLE_ENTITIES.has(entity)) {
            return this.getRandomCached(entity);
        }
        return this.api.get(`random/${entity}`);
    }
    async getRandomCached(entity) {
        const cached = this.cache.get(entity);
        if (cached && cached.length > 0) {
            return cached[Math.floor(Math.random() * cached.length)];
        }
        const record = await this.api.get(`random/${entity}`);
        if (!this.cache.has(entity)) {
            this.cache.set(entity, []);
        }
        this.cache.get(entity).push(record);
        return record;
    }
    constructor(api){
        _define_property(this, "api", void 0);
        _define_property(this, "cache", new Map());
        this.api = api;
    }
};

//# sourceMappingURL=RandomEntityFetcher.js.map