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 MonitorStepLogMonitorUtil {
    static toQuery(monitorStepLogMonitor) {
        const query = {};
        if (monitorStepLogMonitor.telemetryServiceIds &&
            monitorStepLogMonitor.telemetryServiceIds.length > 0) {
            query.primaryEntityId = new Includes(monitorStepLogMonitor.telemetryServiceIds);
        }
        // Compiles to hasAny(entityKeys, [...]) server-side. Undefined/empty is a no-op.
        if (monitorStepLogMonitor.entityKeys &&
            monitorStepLogMonitor.entityKeys.length > 0) {
            query.entityKeys = new Includes(monitorStepLogMonitor.entityKeys);
        }
        if (monitorStepLogMonitor.attributes &&
            Object.keys(monitorStepLogMonitor.attributes).length > 0) {
            query.attributes = monitorStepLogMonitor.attributes;
        }
        if (monitorStepLogMonitor.severityTexts &&
            monitorStepLogMonitor.severityTexts.length > 0) {
            query.severityText = new Includes(monitorStepLogMonitor.severityTexts);
        }
        if (monitorStepLogMonitor.body) {
            query.body = new Search(monitorStepLogMonitor.body);
        }
        if (monitorStepLogMonitor.lastXSecondsOfLogs) {
            const endDate = OneUptimeDate.getCurrentDate();
            const startDate = OneUptimeDate.addRemoveSeconds(endDate, monitorStepLogMonitor.lastXSecondsOfLogs * -1);
            query.time = new InBetween(startDate, endDate);
        }
        return query;
    }
    static getDefault() {
        return {
            attributes: {},
            body: "",
            severityTexts: [],
            telemetryServiceIds: [],
            entityKeys: [],
            lastXSecondsOfLogs: 60,
        };
    }
    static fromJSON(json) {
        return {
            attributes: json["attributes"] || {},
            body: json["body"],
            severityTexts: json["severityTexts"],
            telemetryServiceIds: ObjectID.fromJSONArray(json["telemetryServiceIds"]),
            entityKeys: json["entityKeys"] || [],
            lastXSecondsOfLogs: json["lastXSecondsOfLogs"],
        };
    }
    static toJSON(monitor) {
        return {
            attributes: monitor.attributes,
            body: monitor.body,
            severityTexts: monitor.severityTexts,
            telemetryServiceIds: ObjectID.toJSONArray(monitor.telemetryServiceIds),
            entityKeys: monitor.entityKeys || [],
            lastXSecondsOfLogs: monitor.lastXSecondsOfLogs,
        };
    }
}
//# sourceMappingURL=MonitorStepLogMonitor.js.map