001package jmri.jmrix.roco.z21.messageformatters;
002
003import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
004import jmri.jmrix.Message;
005import jmri.jmrix.roco.z21.Z21MessageFormatter;
006import jmri.jmrix.roco.z21.Z21Reply;
007
008/**
009 * Formats Z21 XPressNet Tunnel Reply messages.
010 *
011 * @author Paul Bender Copyright (C) 2025
012 */
013public class Z21XPressNetTunnelReplyFormatter implements Z21MessageFormatter {
014
015    @Override
016    public boolean handlesMessage(Message m) {
017        return m instanceof Z21Reply && ((Z21Reply) m).getOpCode() == 0x0040;
018    }
019
020    @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "cast is checked in handlesMessage")
021    @Override
022    public String formatMessage(Message m) {
023        if(!handlesMessage(m)) {
024            throw new IllegalArgumentException("Message is not a Z21 XPressNet Tunnel Reply");
025        }
026        return Bundle.getMessage("Z21XpressNetTunnelReply", ((Z21Reply) m).getXNetReply().toMonitorString());
027    }
028
029}