var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import CompareCriteria from "./CompareCriteria";
import { CheckOn, FilterType, } from "../../../../Types/Monitor/CriteriaFilter";
import CaptureSpan from "../../Telemetry/CaptureSpan";
export default class DnssecMonitorCriteria {
    static async isMonitorInstanceCriteriaFilterMet(input) {
        const dataToProcess = input.dataToProcess;
        const dnssecResponse = dataToProcess.dnssecResponse;
        if (!dnssecResponse) {
            return null;
        }
        const isTrue = input.criteriaFilter.filterType === FilterType.True;
        const isFalse = input.criteriaFilter.filterType === FilterType.False;
        if (input.criteriaFilter.checkOn === CheckOn.DnssecChainValid) {
            if (dnssecResponse.isChainValid && isTrue) {
                return `DNSSEC chain is valid for ${dnssecResponse.domainName}.`;
            }
            if (!dnssecResponse.isChainValid && isFalse) {
                return `DNSSEC chain validation failed for ${dnssecResponse.domainName}.`;
            }
            return null;
        }
        if (input.criteriaFilter.checkOn === CheckOn.DnssecDnskeyExists) {
            const exists = dnssecResponse.dnskeys.length > 0;
            if (exists && isTrue) {
                return `DNSKEY records present for ${dnssecResponse.domainName}.`;
            }
            if (!exists && isFalse) {
                return `No DNSKEY records found for ${dnssecResponse.domainName}.`;
            }
            return null;
        }
        if (input.criteriaFilter.checkOn === CheckOn.DnssecDsExists) {
            const exists = dnssecResponse.isParentDsPresent;
            if (exists && isTrue) {
                return `DS records present at parent zone for ${dnssecResponse.domainName}.`;
            }
            if (!exists && isFalse) {
                return `No DS records found at the parent zone for ${dnssecResponse.domainName}.`;
            }
            return null;
        }
        if (input.criteriaFilter.checkOn === CheckOn.DnssecResolverConsensus) {
            const consensus = dnssecResponse.resolverConsensusAd;
            if (consensus && isTrue) {
                return `All resolvers report DNSSEC-valid (AD flag) for ${dnssecResponse.domainName}.`;
            }
            if (!consensus && isFalse) {
                return `Resolvers do not agree on DNSSEC validity for ${dnssecResponse.domainName}.`;
            }
            return null;
        }
        if (input.criteriaFilter.checkOn === CheckOn.DnssecNameserverConsistent) {
            const consistent = dnssecResponse.isNameserverConsistent;
            if (consistent && isTrue) {
                return `Authoritative nameservers are consistent for ${dnssecResponse.domainName}.`;
            }
            if (!consistent && isFalse) {
                return `Authoritative nameservers are inconsistent for ${dnssecResponse.domainName}.`;
            }
            return null;
        }
        if (input.criteriaFilter.checkOn === CheckOn.DnssecSignatureExpiresInDays) {
            const threshold = CompareCriteria.convertToNumber(input.criteriaFilter.value);
            if (threshold === null || threshold === undefined) {
                return null;
            }
            if (dnssecResponse.daysUntilSignatureExpiry === undefined) {
                return null;
            }
            return CompareCriteria.compareCriteriaNumbers({
                value: dnssecResponse.daysUntilSignatureExpiry,
                threshold: threshold,
                criteriaFilter: input.criteriaFilter,
            });
        }
        return null;
    }
}
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], DnssecMonitorCriteria, "isMonitorInstanceCriteriaFilterMet", null);
//# sourceMappingURL=DnssecMonitorCriteria.js.map