001package jmri.jmrix.dccpp;
002
003/**
004 * A single DCC-EX EXRAIL Route or Automation entry; state and caption updated via {@code <jB>} replies.
005 *
006 * @author Chad Francis Copyright (C) 2026
007 */
008public class DCCppExrailEntry {
009
010    /** EXRAIL state values from {@code <jB id state>} replies. */
011    public enum State {
012        INACTIVE(0), ACTIVE(1), HIDDEN(2), DISABLED(4);
013
014        public final int value;
015        State(int value) { this.value = value; }
016
017        /** Returns the matching State, or null if the value is unrecognised. */
018        public static State fromValue(int value) {
019            for (State s : values()) {
020                if (s.value == value) return s;
021            }
022            return null;
023        }
024    }
025
026    private final int id;
027    private final String type;
028    private final String description;
029    private String caption;
030    private State state = null; // null = unknown until first <jB> state reply
031
032    public DCCppExrailEntry(int id, String type, String description) {
033        this.id = id;
034        this.type = type;
035        this.description = description;
036    }
037
038    public int getId() { return id; }
039
040    public String getType() { return type; }
041
042    public String getDescription() { return description; }
043
044    public boolean isRoute() { return "R".equals(type); }
045
046    public boolean isAutomation() { return "A".equals(type); }
047
048    /** Caption set via {@code <jB id "caption">}, or null if not yet received. */
049    public String getCaption() { return caption; }
050
051    public void setCaption(String caption) { this.caption = caption; }
052
053    /** Returns caption if set, otherwise description. */
054    public String getDisplayName() {
055        return caption != null ? caption : description;
056    }
057
058    /** State from {@code <jB id state>}; null if not yet received. */
059    public State getState() { return state; }
060
061    public void setState(State state) { this.state = state; }
062}