001package org.clafer.ig;
002
003import java.util.List;
004
005/**
006 * A solution of a model, claferIG's {@code ClaferSolution}: an instance of a
007 * static model, or a trace of a dynamic model, whose states are instances,
008 * with the state to which its last state loops back.
009 */
010public sealed interface Solution {
011
012    /**
013     * @return the instance, or the states of the trace
014     */
015    List<ClaferModel> models();
016
017    /**
018     * An instance, with its text as its backend prints it, if the backend
019     * prints it otherwise than claferIG ({@code null} for claferIG's text).
020     */
021    record Instance(ClaferModel model, String text) implements Solution {
022
023        public Instance(ClaferModel model) {
024            this(model, null);
025        }
026
027        @Override
028        public List<ClaferModel> models() {
029            return List.of(model);
030        }
031    }
032
033    record Trace(List<ClaferModel> states, int loopState) implements Solution {
034
035        public Trace {
036            states = List.copyOf(states);
037        }
038
039        @Override
040        public List<ClaferModel> models() {
041            return states;
042        }
043    }
044}