package org.xyzh.common.core.enums;

/**
 * @description    UserStatus枚举类 用户状态枚举类
 * @filename    UserStatus.java
 * @author    yslg
 * @copyright xyzh
 * @since 2025-09-28
 */
public enum UserStatus {

    NORMAL("0", "正常", "用户状态正常"),
    DISABLED("1", "禁用", "用户被禁用"),
    LOCKED("2", "锁定", "用户被锁定"),
    EXPIRED("3", "过期", "用户已过期"),
    PENDING("4", "待激活", "用户待激活");

    private final String code;
    private final String name;
    private final String description;

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

    /**
     * @description    获取枚举值
     * @return    String 枚举值
     * @author    yslg
     * @since 2025-09-28
     */
    public String getCode() {
        return code;
    }

    /**
     * @description    获取枚举名称
     * @return    String 枚举名称
     * @author    yslg
     * @since 2025-09-28
     */
    public String getName() {
        return name;
    }

    /**
     * @description    获取枚举描述
     * @return    String 枚举描述
     * @author    yslg
     * @since 2025-09-28
     */
    public String getDescription() {
        return description;
    }

    /**
     * @description    根据code获取枚举
     * @param code 状态码
     * @return UserStatus 用户状态枚举
     * @author    yslg
     * @since 2025-09-28
     */
    public static UserStatus fromCode(String code) {
        for (UserStatus status : UserStatus.values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return NORMAL;
    }
}
