import InBetween from "../BaseDatabase/InBetween";
import Includes from "../BaseDatabase/Includes";
import Search from "../BaseDatabase/Search";
import OneUptimeDate from "../Date";
import ObjectID from "../ObjectID";
export class MonitorStepExceptionMonitorUtil {
    static toAnalyticsQuery(monitorStepExceptionMonitor) {
        const query = {};
        if (monitorStepExceptionMonitor.telemetryServiceIds &&
            monitorStepExceptionMonitor.telemetryServiceIds.length > 0) {
            query.primaryEntityId = new Includes(monitorStepExceptionMonitor.telemetryServiceIds);
        }
        // Compiles to hasAny(entityKeys, [...]) server-side. Undefined/empty is a no-op.
        if (monitorStepExceptionMonitor.entityKeys &&
            monitorStepExceptionMonitor.entityKeys.length > 0) {
            query.entityKeys = new Includes(monitorStepExceptionMonitor.entityKeys);
        }
        if (monitorStepExceptionMonitor.exceptionTypes &&
            monitorStepExceptionMonitor.exceptionTypes.length > 0) {
            query.exceptionType = new Includes(monitorStepExceptionMonitor.exceptionTypes);
        }
        if (monitorStepExceptionMonitor.message) {
            query.message = new Search(monitorStepExceptionMonitor.message);
        }
        if (monitorStepExceptionMonitor.lastXSecondsOfExceptions) {
            const endDate = OneUptimeDate.getCurrentDate();
            const startDate = OneUptimeDate.addRemoveSeconds(endDate, monitorStepExceptionMonitor.lastXSecondsOfExceptions * -1);
            query.time = new InBetween(startDate, endDate);
        }
        return query;
    }
    static getDefault() {
        return {
            telemetryServiceIds: [],
            entityKeys: [],
            exceptionTypes: [],
            message: "",
            includeResolved: false,
            includeArchived: false,
            lastXSecondsOfExceptions: 60,
        };
    }
    static fromJSON(json) {
        return {
            telemetryServiceIds: ObjectID.fromJSONArray(json["telemetryServiceIds"] || []),
            entityKeys: json["entityKeys"] || [],
            exceptionTypes: json["exceptionTypes"] || [],
            message: json["message"] || "",
            includeResolved: Boolean(json["includeResolved"]) || false,
            includeArchived: Boolean(json["includeArchived"]) || false,
            lastXSecondsOfExceptions: json["lastXSecondsOfExceptions"] || 60,
        };
    }
    static toJSON(monitor) {
        return {
            telemetryServiceIds: ObjectID.toJSONArray(monitor.telemetryServiceIds),
            entityKeys: monitor.entityKeys || [],
            exceptionTypes: monitor.exceptionTypes,
            message: monitor.message,
            includeResolved: monitor.includeResolved,
            includeArchived: monitor.includeArchived,
            lastXSecondsOfExceptions: monitor.lastXSecondsOfExceptions,
        };
    }
}
//# sourceMappingURL=MonitorStepExceptionMonitor.js.map