"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchEvent = fetchEvent;
exports.convertClientEventToHubEvent = convertClientEventToHubEvent;
const PropertyMapper_1 = require("./_internal/PropertyMapper");
const getPropertyMap_1 = require("./_internal/getPropertyMap");
const events_1 = require("./api/events");
/**
 * @private
 * Get an Event by id or slug
 * @param identifier event id or slug
 * @param requestOptions request options
 * @returns a promise that resolves an IHubEvent
 */
function fetchEvent(eventId, requestOptions) {
    const spl = eventId.split("-");
    const id = spl[spl.length - 1];
    return (0, events_1.getEvent)(Object.assign({ eventId: id, data: {
            include: "associations",
        } }, requestOptions))
        .then((event) => convertClientEventToHubEvent(event, requestOptions))
        .catch(() => {
        throw new Error("Failed to fetch event.");
    });
}
/**
 * @private
 * Convert a client event record into a Hub Event
 * @param clientEvent the client event record
 * @param requestOptions request options
 * @returns a promise that resolves a IHubEvent
 */
async function convertClientEventToHubEvent(clientEvent, _requestOptions) {
    const mapper = new PropertyMapper_1.EventPropertyMapper((0, getPropertyMap_1.getPropertyMap)());
    return Promise.resolve(mapper.storeToEntity(clientEvent, {}));
}
//# sourceMappingURL=fetch.js.map