package com.lingniu.ingest.protocol.jt808.model;

/**
 * JT/T 808 消息 ID 常量集（节选核心消息，按需继续扩展）。
 *
 * <p>使用常量类而非 enum：808 消息种类多（超过 80 个），新增高频，常量类比 enum 维护成本更低。
 */
public final class Jt808MessageId {

    private Jt808MessageId() {}

    // ===== 终端上行 =====
    public static final int TERMINAL_GENERAL_RESPONSE = 0x0001;
    public static final int TERMINAL_HEARTBEAT        = 0x0002;
    public static final int TERMINAL_UNREGISTER       = 0x0003;
    public static final int TERMINAL_REGISTER         = 0x0100;
    public static final int TERMINAL_AUTH             = 0x0102;
    public static final int TERMINAL_PARAMS_REPORT    = 0x0104;
    public static final int TERMINAL_ATTRS_REPORT     = 0x0107;
    public static final int TERMINAL_LOCATION         = 0x0200;
    public static final int TERMINAL_LOCATION_BATCH   = 0x0704;
    public static final int TERMINAL_EVENT_REPORT     = 0x0301;
    public static final int TERMINAL_CAN_DATA_REPORT  = 0x0705;
    public static final int TERMINAL_MEDIA_EVENT      = 0x0800;
    public static final int TERMINAL_MEDIA_UPLOAD     = 0x0801;
    public static final int TERMINAL_PASSTHROUGH      = 0x0900;

    // ===== 平台下行 =====
    public static final int PLATFORM_GENERAL_RESPONSE = 0x8001;
    public static final int PLATFORM_REGISTER_ACK     = 0x8100;
    public static final int PLATFORM_SET_PARAMS       = 0x8103;
    public static final int PLATFORM_QUERY_PARAMS     = 0x8104;
    public static final int PLATFORM_TERMINAL_CONTROL = 0x8105;
    public static final int PLATFORM_QUERY_ATTRS      = 0x8107;
    public static final int PLATFORM_QUERY_LOCATION   = 0x8201;
    public static final int PLATFORM_TRACK_CONTROL    = 0x8202;
    public static final int PLATFORM_ALARM_ACK        = 0x8203;
    public static final int PLATFORM_DELETE_CIRCLE_AREA = 0x8601;

    public static String nameOf(int messageId) {
        return switch (messageId) {
            case TERMINAL_GENERAL_RESPONSE -> "TERMINAL_GENERAL_RESPONSE";
            case TERMINAL_HEARTBEAT -> "TERMINAL_HEARTBEAT";
            case TERMINAL_UNREGISTER -> "TERMINAL_UNREGISTER";
            case TERMINAL_REGISTER -> "TERMINAL_REGISTER";
            case TERMINAL_AUTH -> "TERMINAL_AUTH";
            case TERMINAL_PARAMS_REPORT -> "TERMINAL_PARAMS_REPORT";
            case TERMINAL_ATTRS_REPORT -> "TERMINAL_ATTRS_REPORT";
            case TERMINAL_LOCATION -> "TERMINAL_LOCATION";
            case TERMINAL_LOCATION_BATCH -> "TERMINAL_LOCATION_BATCH";
            case TERMINAL_EVENT_REPORT -> "TERMINAL_EVENT_REPORT";
            case TERMINAL_CAN_DATA_REPORT -> "TERMINAL_CAN_DATA_REPORT";
            case TERMINAL_MEDIA_EVENT -> "TERMINAL_MEDIA_EVENT";
            case TERMINAL_MEDIA_UPLOAD -> "TERMINAL_MEDIA_UPLOAD";
            case TERMINAL_PASSTHROUGH -> "TERMINAL_PASSTHROUGH";
            case PLATFORM_GENERAL_RESPONSE -> "PLATFORM_GENERAL_RESPONSE";
            case PLATFORM_REGISTER_ACK -> "PLATFORM_REGISTER_ACK";
            case PLATFORM_SET_PARAMS -> "PLATFORM_SET_PARAMS";
            case PLATFORM_QUERY_PARAMS -> "PLATFORM_QUERY_PARAMS";
            case PLATFORM_TERMINAL_CONTROL -> "PLATFORM_TERMINAL_CONTROL";
            case PLATFORM_QUERY_ATTRS -> "PLATFORM_QUERY_ATTRS";
            case PLATFORM_QUERY_LOCATION -> "PLATFORM_QUERY_LOCATION";
            case PLATFORM_TRACK_CONTROL -> "PLATFORM_TRACK_CONTROL";
            case PLATFORM_ALARM_ACK -> "PLATFORM_ALARM_ACK";
            case PLATFORM_DELETE_CIRCLE_AREA -> "PLATFORM_DELETE_CIRCLE_AREA";
            default -> "UNKNOWN_0x" + hex(messageId);
        };
    }

    public static String reportTypeOf(int messageId) {
        return switch (messageId) {
            case TERMINAL_LOCATION -> "LOCATION";
            case TERMINAL_LOCATION_BATCH -> "LOCATION_BATCH";
            case TERMINAL_HEARTBEAT -> "HEARTBEAT";
            case TERMINAL_AUTH -> "AUTH";
            case TERMINAL_REGISTER -> "REGISTER";
            case TERMINAL_UNREGISTER -> "UNREGISTER";
            case TERMINAL_GENERAL_RESPONSE -> "TERMINAL_RESPONSE";
            case TERMINAL_PARAMS_REPORT -> "PARAMS_REPORT";
            case TERMINAL_ATTRS_REPORT -> "ATTRS_REPORT";
            case TERMINAL_MEDIA_EVENT -> "MEDIA_EVENT";
            case TERMINAL_MEDIA_UPLOAD -> "MEDIA_UPLOAD";
            case TERMINAL_PASSTHROUGH -> "PASSTHROUGH";
            default -> "RAW";
        };
    }

    public static String hex(int messageId) {
        return String.format("%04X", messageId & 0xFFFF);
    }
}
