import ModelAPI from "../Utils/ModelAPI/ModelAPI";
import { LIMIT_PER_PROJECT } from "../../Types/Database/LimitMax";
import StatusPageResource from "../../Models/DatabaseModels/StatusPageResource";
import DropdownUtil from "./Dropdown";
import StatusPageEventType from "../../Types/StatusPage/StatusPageEventType";
export default class StatusPageUtil {
    static getDropdownPropsBasedOnEventTypes() {
        return DropdownUtil.getDropdownOptionsFromEnum(StatusPageEventType);
    }
    static async getCategoryCheckboxPropsBasedOnResources(statusPageId, overrideRequestUrl) {
        const categories = [];
        const options = [];
        let resources = await StatusPageUtil.getResources(statusPageId, overrideRequestUrl);
        let resourceGroups = resources
            .map((resource) => {
            return resource.statusPageGroup;
        })
            .filter((group) => {
            return Boolean(group);
        });
        // now sort by order.
        resourceGroups = resourceGroups.sort((a, b) => {
            return a.order - b.order;
        });
        // add categories.
        resourceGroups.forEach((group) => {
            //before we add make sure it doesn't already exist.
            if (categories.find((category) => {
                return category.id === group._id;
            })) {
                return;
            }
            categories.push({
                id: group._id,
                title: group.name,
            });
        });
        // sort resources by order.
        resources = resources.sort((a, b) => {
            return a.order - b.order;
        });
        // add options.
        resources.forEach((resource) => {
            var _a;
            options.push({
                value: resource._id,
                label: resource.displayName,
                categoryId: ((_a = resource.statusPageGroup) === null || _a === void 0 ? void 0 : _a._id) || "",
            });
        });
        return {
            categories,
            options,
        };
    }
    static async getResources(statusPageId, overrideRequestUrl) {
        const resources = await ModelAPI.getList({
            modelType: StatusPageResource,
            query: {
                statusPageId: statusPageId,
            },
            limit: LIMIT_PER_PROJECT,
            skip: 0,
            select: {
                _id: true,
                displayName: true,
                order: true,
                statusPageGroup: {
                    _id: true,
                    name: true,
                    order: true,
                },
            },
            sort: {},
            requestOptions: overrideRequestUrl
                ? {
                    overrideRequestUrl: overrideRequestUrl,
                }
                : undefined,
        });
        return resources.data;
    }
}
//# sourceMappingURL=StatusPage.js.map