export default class MonitorCriteriaDataExtractor {
    static getProbeMonitorResponse(dataToProcess) {
        if (dataToProcess.monitorStepId) {
            return dataToProcess;
        }
        return null;
    }
    static getServerMonitorResponse(dataToProcess) {
        if (dataToProcess.hostname) {
            return dataToProcess;
        }
        return null;
    }
    static getIncomingMonitorRequest(dataToProcess) {
        if (dataToProcess.incomingRequestReceivedAt !==
            undefined) {
            return dataToProcess;
        }
        return null;
    }
    static getLogMonitorResponse(dataToProcess) {
        if (dataToProcess.logCount !== undefined) {
            return dataToProcess;
        }
        return null;
    }
    static getTraceMonitorResponse(dataToProcess) {
        if (dataToProcess.spanCount !== undefined) {
            return dataToProcess;
        }
        return null;
    }
    static getMetricMonitorResponse(dataToProcess) {
        if (dataToProcess.metricResult !== undefined) {
            return dataToProcess;
        }
        return null;
    }
    static getExceptionMonitorResponse(dataToProcess) {
        if (dataToProcess.exceptionCount !== undefined) {
            return dataToProcess;
        }
        return null;
    }
    static getCustomCodeMonitorResponse(dataToProcess) {
        const probeResponse = MonitorCriteriaDataExtractor.getProbeMonitorResponse(dataToProcess);
        if (probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.customCodeMonitorResponse) {
            return probeResponse.customCodeMonitorResponse;
        }
        return null;
    }
    static getSyntheticMonitorResponses(dataToProcess) {
        const probeResponse = MonitorCriteriaDataExtractor.getProbeMonitorResponse(dataToProcess);
        return (probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.syntheticMonitorResponse) || [];
    }
    static getSslResponse(dataToProcess) {
        const probeResponse = MonitorCriteriaDataExtractor.getProbeMonitorResponse(dataToProcess);
        if (probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.sslResponse) {
            return probeResponse.sslResponse;
        }
        return null;
    }
    static extractMetricValues(input) {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
        const metricResponse = MonitorCriteriaDataExtractor.getMetricMonitorResponse(input.dataToProcess);
        if (!metricResponse) {
            return null;
        }
        const aggregatedResults = metricResponse.metricResult || [];
        if (!aggregatedResults.length) {
            return {
                alias: ((_a = input.criteriaFilter.metricMonitorOptions) === null || _a === void 0 ? void 0 : _a.metricAlias) || null,
                values: [],
            };
        }
        let alias = ((_b = input.criteriaFilter.metricMonitorOptions) === null || _b === void 0 ? void 0 : _b.metricAlias) || null;
        let result;
        if (alias) {
            const queryConfigs = ((_e = (_d = (_c = input.monitorStep.data) === null || _c === void 0 ? void 0 : _c.metricMonitor) === null || _d === void 0 ? void 0 : _d.metricViewConfig) === null || _e === void 0 ? void 0 : _e.queryConfigs) ||
                [];
            let aliasIndex = queryConfigs.findIndex((queryConfig) => {
                var _a;
                return ((_a = queryConfig.metricAliasData) === null || _a === void 0 ? void 0 : _a.metricVariable) === alias;
            });
            if (aliasIndex < 0) {
                const formulaConfigs = ((_h = (_g = (_f = input.monitorStep.data) === null || _f === void 0 ? void 0 : _f.metricMonitor) === null || _g === void 0 ? void 0 : _g.metricViewConfig) === null || _h === void 0 ? void 0 : _h.formulaConfigs) || [];
                const formulaIndex = formulaConfigs.findIndex((formulaConfig) => {
                    var _a;
                    return ((_a = formulaConfig.metricAliasData) === null || _a === void 0 ? void 0 : _a.metricVariable) === alias;
                });
                if (formulaIndex >= 0) {
                    aliasIndex = queryConfigs.length + formulaIndex;
                }
            }
            if (aliasIndex >= 0 && aliasIndex < aggregatedResults.length) {
                result = aggregatedResults[aliasIndex];
            }
        }
        if (!result) {
            result = aggregatedResults[0];
            if (!alias) {
                const defaultAlias = (_p = (_o = (_m = (_l = (_k = (_j = input.monitorStep.data) === null || _j === void 0 ? void 0 : _j.metricMonitor) === null || _k === void 0 ? void 0 : _k.metricViewConfig) === null || _l === void 0 ? void 0 : _l.queryConfigs) === null || _m === void 0 ? void 0 : _m[0]) === null || _o === void 0 ? void 0 : _o.metricAliasData) === null || _p === void 0 ? void 0 : _p.metricVariable;
                alias = defaultAlias || null;
            }
        }
        if (!result) {
            return {
                alias: alias,
                values: [],
            };
        }
        const values = result.data
            .map((entry) => {
            return entry.value;
        })
            .filter((value) => {
            return typeof value === "number" && !isNaN(value);
        });
        return {
            alias: alias,
            values: values,
        };
    }
}
//# sourceMappingURL=MonitorCriteriaDataExtractor.js.map