"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchItemScheduleEnrichment = fetchItemScheduleEnrichment;
const manageSchedule_1 = require("../manageSchedule");
/**
 * @private
 *
 * Fetches the schedule enrichment for a content item. The enrichment will only be fetched if the item
 * is eligible for download scheduling and the user has permission to view the schedule. In cases
 * where the schedule cannot be fetched, the function will return undefined.
 *
 * @param item
 * @param requestOptions
 * @returns the schedule enrichment or undefined
 */
async function fetchItemScheduleEnrichment(item, requestOptions) {
    let result;
    if ((0, manageSchedule_1.isDownloadSchedulingAvailable)(requestOptions, item.access)) {
        try {
            // fetch schedule and add it to enrichments if it exists in schedule API
            const { schedule } = await (0, manageSchedule_1.getSchedule)(item.id, requestOptions);
            result = schedule || { mode: "automatic" };
        }
        catch (error) {
            /* tslint:disable no-console */
            console.warn("Failed to fetch schedule for item", item.id, error);
        }
    }
    return result;
}
//# sourceMappingURL=fetchItemScheduleEnrichment.js.map