package com.wzj.soopin.member.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 用户类型枚举
 */
@Getter
@AllArgsConstructor
public enum UserTypeEnum {

    TENANT(1, "租户"),
    MEMBER(2, "会员");

    private final Integer code;
    private final String desc;

    public static String getDesc(Integer code) {
        if (code == null) {
            return "";
        }
        for (UserTypeEnum type : values()) {
            if (type.getCode().equals(code)) {
                return type.getDesc();
            }
        }
        return "";
    }

    /**
     * 根据账户类型判断用户类型
     * 1-用户 -> 会员, 2-商家 -> 租户, 3-代理 -> 租户, 4-平台 -> 租户
     */
    public static Integer getUserTypeByAccountType(Integer accountType) {
        if (accountType == null) {
            return MEMBER.getCode();
        }
        // 1-用户是会员，其他都是租户
        return accountType == 1 ? MEMBER.getCode() : TENANT.getCode();
    }
}
