package cn.reghao.oss.api.constant;

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

/**
 * 描述资源可被看见的范围
 *
 * @author reghao
 * @date 2023-05-19 18:15:45
 */
public enum ObjectScope {
    PRIVATE(1, "本人可见"),
    PUBLIC(2, "所有人可见"),
    PROTECT(3, "VIP 可见"),
    FRIEND(4, "验证码可见");

    private final int code;
    private final String desc;

    private static Map<Integer, String> descMap = new HashMap<>();
    static {
        for (ObjectScope scope : ObjectScope.values()) {
            descMap.put(scope.code, scope.desc);
        }
    }

    ObjectScope(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getName() {
        return this.name();
    }

    /**
     * 提供给 @ValidEnum 调用
     *
     * @param
     * @return
     * @date 2023-10-11 14:44:42
     */
    public int getValue() {
        return this.code;
    }

    public Integer getCode() {
        return code;
    }

    // TODO 第一次调用时会初始化 descMap
    public static String getDescByCode(int code) {
        return descMap.get(code);
    }
}
