export const HARDCODED_DEFAULT_TELEMETRY_RETENTION_IN_DAYS = 15;
function pickPositive(value) {
    return typeof value === "number" && value > 0 ? value : null;
}
function getBucketValue(config, pillar, bucketKey) {
    var _a, _b;
    if (!config || bucketKey === undefined || bucketKey === null) {
        return null;
    }
    if (pillar === "logs") {
        const bySeverity = (_a = config.logs) === null || _a === void 0 ? void 0 : _a.bySeverity;
        return pickPositive(bySeverity === null || bySeverity === void 0 ? void 0 : bySeverity[bucketKey]);
    }
    if (pillar === "traces") {
        const byStatus = (_b = config.traces) === null || _b === void 0 ? void 0 : _b.byStatus;
        return pickPositive(byStatus === null || byStatus === void 0 ? void 0 : byStatus[bucketKey]);
    }
    return null;
}
function getPillarDefault(config, pillar) {
    var _a;
    if (!config) {
        return null;
    }
    return pickPositive((_a = config[pillar]) === null || _a === void 0 ? void 0 : _a.default);
}
export function resolveTelemetryRetentionInDays(input) {
    const { pillar, bucketKey, serviceConfig, serviceRetentionInDays, projectConfig, projectRetentionInDays, } = input;
    const candidates = [
        getBucketValue(serviceConfig, pillar, bucketKey),
        getPillarDefault(serviceConfig, pillar),
        pickPositive(serviceRetentionInDays),
        getBucketValue(projectConfig, pillar, bucketKey),
        getPillarDefault(projectConfig, pillar),
        pickPositive(projectRetentionInDays),
    ];
    for (const value of candidates) {
        if (value !== null) {
            return value;
        }
    }
    return HARDCODED_DEFAULT_TELEMETRY_RETENTION_IN_DAYS;
}
//# sourceMappingURL=TelemetryRetentionConfig.js.map