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