package com.example.myapplication.util;

import java.util.EnumSet;
import java.util.HashMap;

public enum SenXorEvkCommand
{
    WREG(0,  "WREG"),
    RREG(1,  "RREG"),
    WRSE(2,  "WRSE"),
    RRSE(3, "RRSE"),
    RRAL(4,  "RRAL"),
    WEEP(5,  "WEEP"),
    REEP(6,  "REEP"),
    WFLA(7,  "WFLA"),
    RFLA(8,  "RFLA"),
    GFRA(9,  "GFRA"),
    GFAV(10,  "GFAV"),
    GFRC(11, "GFRC"),
    WCAL(12, "WCAL"),
    SFMO(13, "SFMO"),
    SCMO(14, "SCMO"),
    CCAP(15, "CCAP"),
    DACA(16, "DACA"),
    TEST(17, "TEST"),
    SERR(18, "SERR"),
    FTES(19, "FTES");

    public static String WREG_B4_HEADER_SUBSTR = "#000CWREGB4";
    public static String RREG_HEADER_SUBSTR = "#000ARREG";
    public static String RRSE_HEADER_SUBSTR = "#000CRRSE";
    public static String RRSE_FW_VERSION_SUBSTR = "#000ERRSEB2B3FF";
    public static String RRSE_MODULE_SN_SUBSTR = "#0016RRSEE0E1E2E3E4E5FF";
    public static String RRSE_SENXOR_MODULE_TYPE_SUBSTR = "#000ERRSEBABBFF";

    public static String REDUCE_NETD_X_HEADER = "#000CWREGD6";
    public static String REDUCE_NETD_Y_HEADER = "#000CWREGD7";
    public static String WREG_HEADER = "#000CWREG";

    public static String SENXOR_EVK_CMD_START_CONTINUOUS = "#000CWREGB10302DE";
    public static String SENXOR_EVK_CMD_STOP_CONTINUOUS = "#000CWREGB10002DB";
    public static String SENXOR_EVK_CMD_START_TEMPORAL = "#000CWREGD00102DD";
    public static String SENXOR_EVK_CMD_STOP_TEMPORAL = "#000CWREGD00002DC";
    public static String SENXOR_EVK_CMD_DEFAULT_TEMPORAL = "#000CWREGD16402E7";
    public static String SENXOR_EVK_CMD_DEFAULT_FPS = "#000CWREGB40402F3";

    // Utility static Hashmap
    private static final HashMap<String, SenXorEvkCommand> MAP_STRING_TO_CMD = new HashMap<>();
    private static final HashMap<Integer, SenXorEvkCommand> MAP_INDEX_TO_CMD = new HashMap<>();
    static {
        // Populate the utility static HashMap
        EnumSet<SenXorEvkCommand> set = EnumSet.allOf(SenXorEvkCommand.class);
        for (SenXorEvkCommand cmd : set) {
            MAP_STRING_TO_CMD.put(cmd.getCmdName(), cmd);
            MAP_INDEX_TO_CMD.put(cmd.getIndex(), cmd);
        }
    }

    private final int mIndex;
    private final String mCmdName;

    SenXorEvkCommand(int index, String cmdName) {
        mIndex = index;
        mCmdName = cmdName;
    }

    // returns the EvkCommand object that matches the string, or null
    public static SenXorEvkCommand fromString(String s) {
        return MAP_STRING_TO_CMD.get(s);
    }

    public static SenXorEvkCommand fromIndex(int idx) {
        return MAP_INDEX_TO_CMD.get(idx);
    }

    public int getIndex() { return mIndex; }
    public String getCmdName() { return mCmdName; }
} // end public enum EvkCommand