package com.lingniu.ingest.inbound.xinda;

public record XindaPushMessage(String command, String json) {

    public XindaPushMessage {
        command = command == null ? "" : command.trim();
        json = json == null ? "" : json;
    }

    public int commandCode() {
        if (command.isBlank()) {
            return 0;
        }
        try {
            return Integer.parseInt(command, 16);
        } catch (NumberFormatException e) {
            return 0;
        }
    }

    public boolean malformedCommand() {
        if (command.isBlank()) {
            return false;
        }
        try {
            Integer.parseInt(command, 16);
            return false;
        } catch (NumberFormatException e) {
            return true;
        }
    }
}
