package com.neptune.plugin;

public enum NeptuneErrors {
    NEPTUNE_ERR_OK          ("NEPTUNE_ERR_OK"),
    NEPTUNE_ERR_MAG_OPEN    ("NEPTUNE_ERR_MAG_OPEN"),
    NEPTUNE_ERR_MAG_CLOSE   ("NEPTUNE_ERR_MAG_CLOSE"),
    NEPTUNE_ERR_MAG_READ    ("NEPTUNE_ERR_MAG_READ"),
    NEPTUNE_ERR_MAG_RESET   ("NEPTUNE_ERR_MAG_RESET"),
    NEPTUNE_ERR_PIN_GET    ("NEPTUNE_ERR_PIN_GET"),
    NEPTUNE_ERR_JSONOBJECT_INCORRECT   ("NEPTUNE_ERR_JSONOBJECT_INCORRECT"),
    NEPTUNE_ERR_JSONOBJECT_GENERATE   ("NEPTUNE_ERR_JSONOBJECT_GENERATE"),
    NEPTUNE_ERR_UNKNOWN     ("NEPTUNE_ERR_MAG_UNKNOWN")
    ;

    private int code;
    private String value;

    private NeptuneErrors() {}

    private NeptuneErrors(String _desc) {
        this.code=Counter.nextValue;
        Counter.nextValue++;
        this.value = _desc;
    }

    public String desc() {
        return this.value;
    }
    public int code() {
        return this.code;
    }

    public static NeptuneErrors fromId(int id) {
        for (NeptuneErrors type : values()) {
            if (type.code() == id) {
                return type;
            }
        }
        return NEPTUNE_ERR_UNKNOWN;
    }

    private static class Counter {
        private static int nextValue = 0;
    }


}
