package org.xyzh.auth.enums;

/**
 * @description    用户状态枚举
 * @filename    UserStatus.java
 * @author    yslg
 * @copyright yslg
 * @since 2025-12-09
 */
public enum UserStatus {
    
    NORMAL("0", "正常"),
    DISABLED("1", "禁用"),
    LOCKED("2", "锁定"),
    EXPIRED("3", "过期");

    private final String code;
    private final String name;

    UserStatus(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    /**
     * 根据状态码获取用户状态
     * @param code 状态码
     * @return UserStatus
     */
    public static UserStatus fromCode(String code) {
        if (code == null) {
            return DISABLED;
        }
        for (UserStatus status : values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        return DISABLED; // 默认返回禁用状态
    }

    /**
     * 判断是否为正常状态
     * @return boolean
     */
    public boolean isNormal() {
        return this == NORMAL;
    }
}
