import Zod from "../../Utils/Schema/Zod";
export var CheckOn;
(function (CheckOn) {
    CheckOn["ResponseTime"] = "Response Time (in ms)";
    CheckOn["ResponseStatusCode"] = "Response Status Code";
    CheckOn["ResponseHeader"] = "Response Header";
    CheckOn["ResponseHeaderValue"] = "Response Header Value";
    CheckOn["ResponseBody"] = "Response Body";
    CheckOn["IsOnline"] = "Is Online";
    CheckOn["IncomingRequest"] = "Incoming Request";
    CheckOn["ServerProcessName"] = "Server Process Name";
    CheckOn["ServerProcessCommand"] = "Server Process Command";
    CheckOn["ServerProcessPID"] = "Server Process PID";
    CheckOn["RequestBody"] = "Request Body";
    CheckOn["RequestHeader"] = "Request Header";
    CheckOn["RequestHeaderValue"] = "Request Header Value";
    CheckOn["JavaScriptExpression"] = "JavaScript Expression";
    CheckOn["DiskUsagePercent"] = "Disk Usage (in %)";
    CheckOn["CPUUsagePercent"] = "CPU Usage (in %)";
    CheckOn["MemoryUsagePercent"] = "Memory Usage (in %)";
    CheckOn["LoadAverage1Min"] = "Load Average (1 minute)";
    CheckOn["LoadAverage5Min"] = "Load Average (5 minute)";
    CheckOn["LoadAverage15Min"] = "Load Average (15 minute)";
    CheckOn["SwapUsagePercent"] = "Swap Usage (in %)";
    CheckOn["CPUIoWaitPercent"] = "CPU IO Wait (in %)";
    CheckOn["ExpiresInHours"] = "Expires In Hours";
    CheckOn["ExpiresInDays"] = "Expires In Days";
    CheckOn["IsSelfSignedCertificate"] = "Is Self Signed Certificate";
    CheckOn["IsExpiredCertificate"] = "Is Expired Certificate";
    CheckOn["IsValidCertificate"] = "Is Valid Certificate";
    CheckOn["IsNotAValidCertificate"] = "Is Not A Valid Certificate";
    CheckOn["IsRequestTimeout"] = "Is Request Timeout";
    // Custom code or synthetic monitor.
    CheckOn["ResultValue"] = "Result Value";
    CheckOn["Error"] = "Error";
    CheckOn["ExecutionTime"] = "Execution Time (in ms)";
    // synthetic monitors
    CheckOn["ScreenSizeType"] = "Screen Size";
    CheckOn["BrowserType"] = "Browser Type";
    // Log monitors.
    CheckOn["LogCount"] = "Log Count";
    // Trace monitors.
    CheckOn["SpanCount"] = "Span Count";
    // Exception monitors.
    CheckOn["ExceptionCount"] = "Exception Count";
    // Profile monitors.
    CheckOn["ProfileCount"] = "Profile Count";
    // Metric Monitors.
    CheckOn["MetricValue"] = "Metric Value";
    // Incoming Email monitors.
    CheckOn["EmailSubject"] = "Email Subject";
    CheckOn["EmailFrom"] = "Email From Address";
    CheckOn["EmailBody"] = "Email Body";
    CheckOn["EmailTo"] = "Email To Address";
    CheckOn["EmailReceivedAt"] = "Email Received";
    // SNMP monitors.
    CheckOn["SnmpOidValue"] = "SNMP OID Value";
    CheckOn["SnmpOidExists"] = "SNMP OID Exists";
    CheckOn["SnmpResponseTime"] = "SNMP Response Time (in ms)";
    CheckOn["SnmpIsOnline"] = "SNMP Device Is Online";
    // DNS monitors.
    CheckOn["DnsResponseTime"] = "DNS Response Time (in ms)";
    CheckOn["DnsIsOnline"] = "DNS Is Online";
    CheckOn["DnsRecordValue"] = "DNS Record Value";
    CheckOn["DnssecIsValid"] = "DNSSEC Is Valid";
    CheckOn["DnsRecordExists"] = "DNS Record Exists";
    // Domain monitors.
    CheckOn["DomainExpiresDaysIn"] = "Domain Expires In Days";
    CheckOn["DomainRegistrar"] = "Domain Registrar";
    CheckOn["DomainNameServer"] = "Domain Name Server";
    CheckOn["DomainStatusCode"] = "Domain Status Code";
    CheckOn["DomainIsExpired"] = "Domain Is Expired";
    // DNSSEC monitors.
    CheckOn["DnssecChainValid"] = "DNSSEC Chain Is Valid";
    CheckOn["DnssecDnskeyExists"] = "DNSSEC DNSKEY Record Exists";
    CheckOn["DnssecDsExists"] = "DNSSEC DS Record Exists At Parent";
    CheckOn["DnssecSignatureExpiresInDays"] = "DNSSEC Signature Expires In Days";
    CheckOn["DnssecResolverConsensus"] = "DNSSEC Resolver Consensus (AD Flag)";
    CheckOn["DnssecNameserverConsistent"] = "DNSSEC Nameservers Are Consistent";
    // External Status Page monitors.
    CheckOn["ExternalStatusPageIsOnline"] = "External Status Page Is Online";
    CheckOn["ExternalStatusPageOverallStatus"] = "External Status Page Overall Status";
    CheckOn["ExternalStatusPageComponentStatus"] = "External Status Page Component Status";
    CheckOn["ExternalStatusPageActiveIncidents"] = "External Status Page Active Incidents";
    CheckOn["ExternalStatusPageResponseTime"] = "External Status Page Response Time (in ms)";
})(CheckOn || (CheckOn = {}));
export var EvaluateOverTimeType;
(function (EvaluateOverTimeType) {
    EvaluateOverTimeType["Average"] = "Average";
    EvaluateOverTimeType["Sum"] = "Sum";
    EvaluateOverTimeType["MaximumValue"] = "Maximum Value";
    EvaluateOverTimeType["MunimumValue"] = "Minimum Value";
    EvaluateOverTimeType["AllValues"] = "All Values";
    EvaluateOverTimeType["AnyValue"] = "Any Value";
})(EvaluateOverTimeType || (EvaluateOverTimeType = {}));
export var NoDataPolicy;
(function (NoDataPolicy) {
    /*
     * Do not treat missing data as a breach. The criterion simply does
     * not fire. This is the safest default and matches most SaaS tooling.
     */
    NoDataPolicy["Ignore"] = "Ignore";
    /*
     * Treat missing data points as zero. Preserves the original behavior
     * prior to this policy being configurable — useful for counters where
     * "no events" genuinely means zero.
     */
    NoDataPolicy["TreatAsZero"] = "Treat As Zero";
    /*
     * Trigger the criterion as a breach regardless of threshold. Use for
     * heartbeat-style metrics where the absence of data is itself the
     * problem.
     */
    NoDataPolicy["Trigger"] = "Trigger";
})(NoDataPolicy || (NoDataPolicy = {}));
export var AnomalyDetectionSensitivity;
(function (AnomalyDetectionSensitivity) {
    AnomalyDetectionSensitivity["Low"] = "Low";
    AnomalyDetectionSensitivity["Medium"] = "Medium";
    AnomalyDetectionSensitivity["High"] = "High";
})(AnomalyDetectionSensitivity || (AnomalyDetectionSensitivity = {}));
export var AnomalyDetectionMethod;
(function (AnomalyDetectionMethod) {
    /** Rolling mean ± N × population standard deviation. Default. */
    AnomalyDetectionMethod["MeanStddev"] = "Mean & Std Dev";
    /**
     * Rolling median ± N × MAD (Median Absolute Deviation × 1.4826).
     * Robust to skew (latency tails). Phase E — schema is already ready
     * but the evaluator wires it up later.
     */
    AnomalyDetectionMethod["MedianMad"] = "Median & MAD";
})(AnomalyDetectionMethod || (AnomalyDetectionMethod = {}));
export var EvaluateOverTimeMinutes;
(function (EvaluateOverTimeMinutes) {
    EvaluateOverTimeMinutes["TwoMinutes"] = "2";
    EvaluateOverTimeMinutes["ThreeMinutes"] = "3";
    EvaluateOverTimeMinutes["FiveMinutes"] = "5";
    EvaluateOverTimeMinutes["TenMinutes"] = "10";
    EvaluateOverTimeMinutes["FifteenMinutes"] = "15";
    EvaluateOverTimeMinutes["TwentyMinutes"] = "20";
    EvaluateOverTimeMinutes["ThirtyMinutes"] = "30";
    EvaluateOverTimeMinutes["FortyFiveMinutes"] = "45";
    EvaluateOverTimeMinutes["SixtyMinutes"] = "60";
})(EvaluateOverTimeMinutes || (EvaluateOverTimeMinutes = {}));
export var FilterType;
(function (FilterType) {
    FilterType["EqualTo"] = "Equal To";
    FilterType["NotEqualTo"] = "Not Equal To";
    FilterType["GreaterThan"] = "Greater Than";
    FilterType["LessThan"] = "Less Than";
    FilterType["GreaterThanOrEqualTo"] = "Greater Than Or Equal To";
    FilterType["LessThanOrEqualTo"] = "Less Than Or Equal To";
    FilterType["Contains"] = "Contains";
    FilterType["NotContains"] = "Not Contains";
    FilterType["StartsWith"] = "Starts With";
    FilterType["EndsWith"] = "Ends With";
    FilterType["IsEmpty"] = "Is Empty";
    FilterType["IsNotEmpty"] = "Is Not Empty";
    FilterType["True"] = "True";
    FilterType["False"] = "False";
    FilterType["NotRecievedInMinutes"] = "Not Recieved In Minutes";
    FilterType["RecievedInMinutes"] = "Recieved In Minutes";
    FilterType["EvaluatesToTrue"] = "Evaluates To True";
    FilterType["IsExecuting"] = "Is Executing";
    FilterType["IsNotExecuting"] = "Is Not Executing";
    /*
     * Anomaly-detection filter types. The "value" field is unused —
     * sensitivity and method live in metricMonitorOptions.anomalyDetection.
     * The evaluator compares the aggregated metric to the same-hour-of-
     * week baseline computed by the MetricBaselineHourly MV.
     */
    FilterType["AnomalouslyHigh"] = "Anomalously High";
    FilterType["AnomalouslyLow"] = "Anomalously Low";
    FilterType["Anomalous"] = "Anomalous";
})(FilterType || (FilterType = {}));
export class CriteriaFilterUtil {
    /**
     * Whether the filter is anomaly-based. Anomaly filters skip the
     * static threshold value/unit fields and instead read sensitivity
     * from metricMonitorOptions.anomalyDetection.
     */
    static isAnomalyFilterType(filterType) {
        return (filterType === FilterType.AnomalouslyHigh ||
            filterType === FilterType.AnomalouslyLow ||
            filterType === FilterType.Anomalous);
    }
    static hasValueField(data) {
        const { checkOn } = data;
        /*
         * Anomaly filters carry sensitivity in metricMonitorOptions
         * (not in `value`), so suppress the threshold input.
         */
        if (CriteriaFilterUtil.isAnomalyFilterType(data.filterType)) {
            return false;
        }
        if (checkOn === CheckOn.IsOnline ||
            checkOn === CheckOn.SnmpIsOnline ||
            checkOn === CheckOn.DnsIsOnline ||
            checkOn === CheckOn.DomainIsExpired ||
            checkOn === CheckOn.DnssecChainValid ||
            checkOn === CheckOn.DnssecDnskeyExists ||
            checkOn === CheckOn.DnssecDsExists ||
            checkOn === CheckOn.DnssecResolverConsensus ||
            checkOn === CheckOn.DnssecNameserverConsistent ||
            checkOn === CheckOn.ExternalStatusPageIsOnline) {
            return false;
        }
        if (checkOn === CheckOn.IsRequestTimeout) {
            return false;
        }
        if (checkOn === CheckOn.SnmpOidExists ||
            checkOn === CheckOn.DnssecIsValid ||
            checkOn === CheckOn.DnsRecordExists) {
            return false;
        }
        if (checkOn === CheckOn.IsValidCertificate ||
            checkOn === CheckOn.IsSelfSignedCertificate ||
            checkOn === CheckOn.IsExpiredCertificate ||
            checkOn === CheckOn.IsNotAValidCertificate) {
            return false;
        }
        if (FilterType.IsEmpty === data.filterType ||
            FilterType.IsNotEmpty === data.filterType ||
            FilterType.True === data.filterType ||
            FilterType.False === data.filterType) {
            return false;
        }
        return true;
    }
    static getEvaluateOverTimeTypeByCriteriaFilter(criteriaFilter) {
        if (!criteriaFilter) {
            return [];
        }
        if (criteriaFilter.checkOn === CheckOn.IsOnline) {
            return [EvaluateOverTimeType.AllValues, EvaluateOverTimeType.AnyValue];
        }
        return [
            EvaluateOverTimeType.Average,
            EvaluateOverTimeType.Sum,
            EvaluateOverTimeType.MaximumValue,
            EvaluateOverTimeType.MunimumValue,
            EvaluateOverTimeType.AllValues,
            EvaluateOverTimeType.AnyValue,
        ];
    }
    static getInverseFilterType(filterType) {
        switch (filterType) {
            case FilterType.GreaterThan:
                return FilterType.LessThanOrEqualTo;
            case FilterType.LessThan:
                return FilterType.GreaterThanOrEqualTo;
            case FilterType.GreaterThanOrEqualTo:
                return FilterType.LessThan;
            case FilterType.LessThanOrEqualTo:
                return FilterType.GreaterThan;
            case FilterType.EqualTo:
                return FilterType.NotEqualTo;
            case FilterType.NotEqualTo:
                return FilterType.EqualTo;
            default:
                return filterType;
        }
    }
    static isEvaluateOverTimeFilter(checkOn) {
        return (checkOn === CheckOn.ResponseStatusCode ||
            checkOn === CheckOn.ResponseTime ||
            checkOn === CheckOn.DiskUsagePercent ||
            checkOn === CheckOn.CPUUsagePercent ||
            checkOn === CheckOn.MemoryUsagePercent ||
            checkOn === CheckOn.LoadAverage1Min ||
            checkOn === CheckOn.LoadAverage5Min ||
            checkOn === CheckOn.LoadAverage15Min ||
            checkOn === CheckOn.SwapUsagePercent ||
            checkOn === CheckOn.CPUIoWaitPercent ||
            checkOn === CheckOn.IsOnline ||
            checkOn === CheckOn.SnmpResponseTime ||
            checkOn === CheckOn.SnmpIsOnline ||
            checkOn === CheckOn.DnsResponseTime ||
            checkOn === CheckOn.DnsIsOnline ||
            checkOn === CheckOn.ExternalStatusPageResponseTime ||
            checkOn === CheckOn.ExternalStatusPageIsOnline);
    }
}
export const CriteriaFilterSchema = Zod.object({
    checkOn: Zod.string(),
    serverMonitorOptions: Zod.object({
        diskPath: Zod.string().optional(),
    }).optional(),
    metricMonitorOptions: Zod.object({
        metricAlias: Zod.string().optional(),
        metricAggregationType: Zod.string().optional(),
        onNoDataPolicy: Zod.string().optional(),
        thresholdUnit: Zod.string().optional(),
        anomalyDetection: Zod.object({
            sensitivity: Zod.string().optional(),
            method: Zod.string().optional(),
            windowDays: Zod.number().optional(),
            minSamples: Zod.number().optional(),
        }).optional(),
    }).optional(),
    snmpMonitorOptions: Zod.object({
        oid: Zod.string().optional(),
    }).optional(),
    filterType: Zod.string().optional(),
    value: Zod.union([Zod.string(), Zod.number()]).optional(),
    evaluateOverTime: Zod.boolean().optional(),
    evaluateOverTimeOptions: Zod.object({
        timeValueInMinutes: Zod.number().optional(),
        evaluateOverTimeType: Zod.string().optional(),
    }).optional(),
});
//# sourceMappingURL=CriteriaFilter.js.map