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