import { SeverityTypeEnums } from "../../../enums/unitySystemEnums.mjs";
import { NumberOperatorEnums } from "../../../models/NumberOperator.mjs";
//#region src/UI/utilityDisplay/utilities/aggregateUtils.js
const getThresholdStatus = (aggThreshold, aggregateValue) => {
	if (!aggThreshold || !aggregateValue) return null;
	const thresholdTypes = [
		{
			type: SeverityTypeEnums.Success,
			threshold: aggThreshold.successThreshold
		},
		{
			type: SeverityTypeEnums.Error,
			threshold: aggThreshold.errorThreshold
		},
		{
			type: SeverityTypeEnums.Warning,
			threshold: aggThreshold.warningThreshold
		},
		{
			type: SeverityTypeEnums.Info,
			threshold: aggThreshold.infoThreshold
		}
	];
	let thresholdStatus = "";
	for (const { type, threshold } of thresholdTypes) if (threshold && evaluateThreshold(threshold, aggregateValue)) {
		thresholdStatus = type;
		break;
	}
	return thresholdStatus;
};
const evaluateThreshold = (threshold = {}, aggregateValue) => {
	if (typeof threshold === "string") try {
		threshold = JSON.parse(threshold);
	} catch {
		console.error(`Could not parse: ${threshold}`);
		return false;
	}
	const { operator, value1, value2 } = threshold;
	let thresholdMet = false;
	switch (operator) {
		case NumberOperatorEnums.Equals:
			thresholdMet = aggregateValue === parseFloat(value1);
			break;
		case NumberOperatorEnums.Does_Not_Equal:
			thresholdMet = aggregateValue !== parseFloat(value1);
			break;
		case NumberOperatorEnums.Greater_Than:
			thresholdMet = aggregateValue > parseFloat(value1);
			break;
		case NumberOperatorEnums.Less_Than:
			thresholdMet = aggregateValue < parseFloat(value1);
			break;
		case NumberOperatorEnums.Greater_Than_Or_Equal_To:
			thresholdMet = aggregateValue >= parseFloat(value1);
			break;
		case NumberOperatorEnums.Less_Than_Or_Equal_To:
			thresholdMet = aggregateValue <= parseFloat(value1);
			break;
		case NumberOperatorEnums.Between:
			thresholdMet = aggregateValue >= parseFloat(value1) && aggregateValue <= parseFloat(value2);
			break;
		default: break;
	}
	return thresholdMet;
};
//#endregion
export { getThresholdStatus };

//# sourceMappingURL=aggregateUtils.mjs.map