"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.processPostOptions = processPostOptions;
const postSort_1 = require("../../../discussions/api/enums/postSort");
const sortOrder_1 = require("../../../discussions/api/enums/sortOrder");
/**
 * A map of HubSearchPostSortFields to PostSort
 */
const SORT_BY_MAP = {
    body: postSort_1.PostSort.BODY,
    channelId: postSort_1.PostSort.CHANNEL_ID,
    created: postSort_1.PostSort.CREATED_AT,
    modified: postSort_1.PostSort.UPDATED_AT,
    owner: postSort_1.PostSort.CREATOR,
    discussion: postSort_1.PostSort.DISCUSSION,
    editor: postSort_1.PostSort.EDITOR,
    id: postSort_1.PostSort.ID,
    parentId: postSort_1.PostSort.PARENT_ID,
    status: postSort_1.PostSort.STATUS,
    title: postSort_1.PostSort.TITLE,
};
const SORT_ORDER_MAP = {
    desc: sortOrder_1.SortOrder.DESC,
    asc: sortOrder_1.SortOrder.ASC,
};
/**
 * Builds a Partial<ISearchPosts> for the given IHubSearchOptions
 * @param options An IHubSearchOptions object
 * @returns a Partial<ISearchPosts> for the given IHubSearchOptions
 */
function processPostOptions(options) {
    const processedOptions = {};
    // num
    if (options.num > 0) {
        processedOptions.num = options.num;
    }
    // start
    if (options.start > 1) {
        processedOptions.start = options.start;
    }
    // sort order
    if (options.sortOrder && SORT_ORDER_MAP[options.sortOrder]) {
        processedOptions.sortOrder = SORT_ORDER_MAP[options.sortOrder];
    }
    // sort field
    const sortField = SORT_BY_MAP[options.sortField];
    if (sortField) {
        processedOptions.sortBy = sortField;
    }
    return processedOptions;
}
//# sourceMappingURL=processPostOptions.js.map