package click.kamil.springstatemachineexporter.analysis.validation;

import java.util.ArrayList;
import java.util.List;

/**
 * Thrown when {@link AnalysisCanonicalFormValidator} finds enum identifiers that are not
 * package-canonical for the machine's resolved {@code <State, Event>} types.
 */
public class AnalysisCanonicalFormException extends IllegalStateException {

    private final List<AnalysisCanonicalFormValidator.Violation> violations;

    public AnalysisCanonicalFormException(List<AnalysisCanonicalFormValidator.Violation> violations) {
        super(formatMessage(violations));
        this.violations = List.copyOf(violations);
    }

    public List<AnalysisCanonicalFormValidator.Violation> getViolations() {
        return violations;
    }

    private static String formatMessage(List<AnalysisCanonicalFormValidator.Violation> violations) {
        StringBuilder sb = new StringBuilder("Analysis model contains non-canonical enum identifiers:");
        for (AnalysisCanonicalFormValidator.Violation violation : violations) {
            sb.append("\n  - ").append(violation.path())
                    .append(": '").append(violation.actual())
                    .append("' (expected '").append(violation.expected()).append("')");
        }
        return sb.toString();
    }
}
