package com.djhk.common.enums;

import lombok.Getter;

/**
 * ip请求限制相关枚举
 */
public enum AccountBlackLevleEnum {
    LEVEL_ONE(1,0,2,600L,300L,"账号锁定5分钟，并且10分钟内如果再次锁定，将升级为level2"),
    LEVEL_TWO(2,1,3,3000L,1500L,"账号锁定15分钟，并且30分钟内如果再次锁定，将升级为level3"),
    LEVEL_THREE(3,2,null,48 * 60 * 60L,24 * 60 * 60L,"账号锁定1天，并且2天内如果再次锁定，将继续锁定1天"),
    ;

    @Getter
    private Integer level;

    @Getter
    private Integer preLevel;

    @Getter
    private Integer nextLevel;

    @Getter
    private Long levelKeyTimeOut;

    @Getter
    private Long blackKeyTimeOut;

    @Getter
    private String desc;

    private AccountBlackLevleEnum(Integer level, Integer preLevel, Integer nextLevel, Long levelKeyTimeOut, Long blackKeyTimeOut, String desc) {
        this.level = level;
        this.preLevel = preLevel;
        this.nextLevel = nextLevel;
        this.levelKeyTimeOut = levelKeyTimeOut;
        this.blackKeyTimeOut = blackKeyTimeOut;
        this.desc = desc;
    }

    public static AccountBlackLevleEnum getByLevel(Integer level) {
        if (level == null) {
            return null;
        }

        for (AccountBlackLevleEnum levleEnum : AccountBlackLevleEnum.values()) {
            if (level.equals(levleEnum.getLevel())) {
                return levleEnum;
            }
        }

        return null;
    }

    public static AccountBlackLevleEnum getByPreLevel(Integer preLevel) {
        if (preLevel == null) {
            return LEVEL_ONE;
        }

        for (AccountBlackLevleEnum levleEnum : AccountBlackLevleEnum.values()) {
            if (preLevel.equals(levleEnum.getPreLevel())) {
                return levleEnum;
            }
        }

        return LEVEL_THREE;
    }
}
