package com.tomas.ckd_system.lib;

public enum ErrorCode {
    E100(100, "Import file unsuccessful."),
    E101(101, "Invalid username or password."),
    E102(102, "HATC data not found."),
    E103(103, "DAY Unit data not found."),
    E104(104, "Parts content receive not matched."),
    E105(105, "Incorrect checkpoint."),
    E106(106, "Unmatched meiji card."),
    E107(107, "Unmatched packing check sheet barcodes."),
    E108(108, "Schedule not found."),
    E109(109, "Master checkpoint not found."),
    E110(110, "Invalid scanning data format."),
    E111(111, "Unlock password not found."),
    E112(112, "Invalid unlock password."),
    E113(113, "Schedule data not found."),

    E201(201, "Meiji card not found."),
    E202(202, "Packing methods file not found."),
    E300(300, "Cannot connect to web service."),
    E301(301, "Internal error on web server."),
    E302(302, "Web server unreachable."),
    E303(303, "No handheld activated.");
    private final int id;
    private final String det;

    ErrorCode(final int id, final String det) {
        this.id = id;
        this.det = det;
    }

    public int getId() {
        return id;
    }

    public String getDet() { return det; }

    @Override
    public String toString() {
        return String.format("%s[Code:%d]", det, id);
    }

    public static ErrorCode fromId(final int id) {
        for (ErrorCode e : ErrorCode.values()) {
            if (e.id == id) {
                return e;
            }
        }
        return null;
    }
}
