package org.dromara.common.core.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 租户类型枚举 2->商家,3->代理,4->平台,5->达人
 */
@Getter
@AllArgsConstructor
public enum TenantType {

    MERCHANT(2, "商家"),
    AGENT(3, "代理"),
    PLATFORM(4, "平台"),
    REFERENCE(5, "达人");

    private final int type;

    private final String desc;


    public static TenantType valueOf(int type) {
        for (TenantType tenantType : TenantType.values()) {
            if (tenantType.type == type) {
                return tenantType;
            }
        }
        throw new IllegalArgumentException("No enum constant with type " + type);
    }

    public static boolean allowCreateByType(Integer currentTenantType, Integer newTenantType) {
        boolean allow = false;
        if (currentTenantType == PLATFORM.type) {
            // 超级管理租户创建租户没有限制
            allow = true;
        } else if (currentTenantType == TenantType.AGENT.type) {
            // 代理商只能创建商铺或达人
            allow = newTenantType == TenantType.AGENT.type || newTenantType == TenantType.MERCHANT.type || newTenantType == TenantType.REFERENCE.type;
        }
        return allow;
    }
}
