"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.normalizeIntervals=normalizeIntervals,exports.findAlarmThresholds=findAlarmThresholds;var core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp},literal_string_1=()=>{var tmp=require("../../core/lib/private/literal-string");return literal_string_1=()=>tmp,tmp};function normalizeIntervals(intervals,changesAreAbsolute){const full=orderAndCompleteIntervals(intervals);return makeGapsUndefined(full),changesAreAbsolute||makeZerosUndefined(full),combineUndefineds(full),validateAtMostOneUndefined(full),full}function orderAndCompleteIntervals(intervals){if(intervals.length<2)throw new(core_1()).UnscopedValidationError((0,literal_string_1().lit)`RequireLeastIntervals`,"Require at least 2 intervals");for(const interval of intervals)if(interval.lower===void 0&&interval.upper===void 0)throw new(core_1()).UnscopedValidationError((0,literal_string_1().lit)`SupplyLeastUpperLower`,`Must supply at least one of 'upper' or 'lower', got: ${JSON.stringify(interval)}`);for(intervals=intervals.map(x=>({...x})),intervals.sort(comparatorFromKey(x=>x.lower??x.upper));propagateBounds(intervals););const lastIndex=intervals.length-1;intervals[0].lower===void 0&&(intervals[0]={...intervals[0],lower:0}),intervals[lastIndex].upper===void 0&&(intervals[lastIndex]={...intervals[lastIndex],upper:1/0});for(const interval of intervals)if(interval.lower===void 0||interval.upper===void 0)throw new(core_1()).UnscopedValidationError((0,literal_string_1().lit)`CouldDetermineLowerUpper`,`Could not determine the lower and upper bounds for ${JSON.stringify(interval)}`);const completeIntervals=intervals;for(let i=0;ix.change===void 0);if(undef.length>1)throw new(core_1()).UnscopedValidationError((0,literal_string_1().lit)`MostNoChangeInterval`,`Can have at most one no-change interval, got ${JSON.stringify(undef)}`)}function comparatorFromKey(keyFn){return(a,b)=>{const keyA=keyFn(a),keyB=keyFn(b);return keyA=1;i--)intervals[i].lower!==void 0&&intervals[i-1].upper===void 0&&(intervals[i-1]={...intervals[i-1],upper:intervals[i].lower},ret=!0);return ret}function overlap(a,b){return a.lowerb.lower}function last(xs){return xs[xs.length-1]}function findAlarmThresholds(intervals){const gapIndex=intervals.findIndex(x=>x.change===void 0);if(gapIndex!==-1)return{lowerAlarmIntervalIndex:gapIndex>0?gapIndex-1:void 0,upperAlarmIntervalIndex:gapIndex