package com.yeechart.dotMatrix.module.DotMatrix.model.bean;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by 56844 on 2023/5/8.
 */
public enum CodeEnum {
    SUCCESS("SUCCESS", 200, "操作成功!"),
    FAIL("FAIL", 0, "网络异常!"),

    requestTimeout(null, 105, "请求超时!"),
    ;
    private String name;
    private String message;
    private int code;
    private Map map = new HashMap<String, String>();

    private CodeEnum(String name, int code, String message) {
        this.name = name;
        this.code = code;
        this.message = message;
        map.put(code, message);
    }

    public static CodeEnum getByCode(int code) {
        for (CodeEnum it : CodeEnum.values()) {
            if (it.getCode() == code) {
                return it;
            }
        }
        return null;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Integer getCodeInteger() {
        return code;
    }

    public String getMessage(String code) {
        return map.get(code) + "";
    }
}
