package cz.senslog.analytics.utils.newvalidator;

import cz.senslog.analytics.domain.AttributeType;

import java.util.List;

public record ValidationResult(double violatedValue, AttributeType violatedAttribute, List<Threshold.Dimension.Rule> rules) {

    public boolean hasViolation() {
        return rules != null && !rules.isEmpty();
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder(violatedAttribute.name().toLowerCase()).append(": ");
        if (rules != null && !rules.isEmpty()) {
            Threshold.Dimension.Rule r0 = rules.get(0);
            result.append(String.format("%.2f %s %.2f", violatedValue, r0.comparisonOperator().format(), r0.value()));
            for (int i = 1; i < rules.size(); i++) {
                Threshold.Dimension.Rule ri = rules.get(i);
                result.append(String.format(" AND %.2f %s %.2f", violatedValue, ri.comparisonOperator().format(), ri.value()));
            }
        } else {
            result.append(String.format("%.2f", violatedValue));
        }
        return result.toString();
    }
}