package com.diagbot.enums;

import com.diagbot.core.KeyedNamed;
import lombok.Setter;

/**
 * @Description: 常量枚举类
 * @Author: ztg
 * @Date: 2018/9/28 10:45
 */
public enum ConstantEnum implements KeyedNamed {

    //TODO 短信过期时间，上线后设为3，测试阶段设大
    SMS_EXPIRED_INTERVAL(99999, "短信失效时间(分钟)"),

    IMG_EXPIRED_INTERVAL(20, "图片验证码失效时间(分钟)");

    @Setter
    private Integer key;

    @Setter
    private String name;

    ConstantEnum(Integer key, String name) {
        this.key = key;
        this.name = name;
    }

    public static ConstantEnum getEnum(Integer key) {
        for (ConstantEnum item : ConstantEnum.values()) {
            if (item.key == key) {
                return item;
            }
        }
        return null;
    }

    public static String getName(Integer key) {
        ConstantEnum item = getEnum(key);
        return item != null ? item.name : null;
    }

    @Override
    public int getKey() {
        return key;
    }

    @Override
    public String getName() {
        return name;
    }
}

