"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.eventToSearchResult = eventToSearchResult;
const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
const computeLinks_1 = require("../../../events/_internal/computeLinks");
const getLocationFromEvent_1 = require("../../../events/_internal/getLocationFromEvent");
/**
 * Resolves an IHubSearchResult for the given IEvent record
 * @param event An IEvent record
 * @param options An IHubSearchOptions object
 * @returns a IHubSearchResult for the given IEvent record
 */
async function eventToSearchResult(event, options) {
    var _a;
    let ownerUser;
    if ((_a = options.include) === null || _a === void 0 ? void 0 : _a.includes("ownerUser")) {
        ownerUser = await (0, arcgis_rest_portal_1.getUser)(Object.assign({ username: event.creator.username }, options.requestOptions));
    }
    const result = {
        access: event.access.toLowerCase(),
        id: event.id,
        location: (0, getLocationFromEvent_1.getLocationFromEvent)(event),
        type: "Event",
        name: event.title,
        owner: event.creator.username,
        ownerUser,
        summary: event.summary || event.description,
        createdDate: new Date(event.createdAt),
        createdDateSource: "event.createdAt",
        updatedDate: new Date(event.updatedAt),
        updatedDateSource: "event.updatedAt",
        family: "event",
        links: (0, computeLinks_1.computeLinks)(event),
        tags: event.tags,
        categories: event.categories,
        rawResult: event,
    };
    return result;
}
//# sourceMappingURL=eventToSearchResult.js.map