/*
 * Copyright (c) 京北方信息技术股份有限公司 Corporation 2021 . All rights reserved.
 *
 */
package net.northking.cctp.common.saas;

import net.northking.cctp.common.saas.cache.StaticTenantCache;

/**
 * SaaS模式上下文
 *
 * @author : xiusong.xie
 * @version : 1.0
 */
public class SaaSContext
{
  /**
   * 租户ID
   */
  private static final ThreadLocal<String> TENANT_ID = new ThreadLocal<>();

  /**
   * 域名
   */
  private static final ThreadLocal<String> DOMAINS = new ThreadLocal<>();

  /**
   * 设置当前线程的 租户ID
   *
   * @param tenantId 租户ID
   */
  public static void setTenantId(String tenantId)
  {
    TENANT_ID.set(tenantId);
  }

  /**
   * 获取当前线程的 租户ID
   *
   * @return 租户ID
   */
  public static String getTenantId()
  {
    return StaticTenantCache.getDefaultTenantId();
  }


  public static void setDomains(String schemaSuffix)
  {
    DOMAINS.set(schemaSuffix);
  }

  public static String getDomains()
  {
    return DOMAINS.get();
  }

  public static void unload()
  {
    TENANT_ID.remove();
    DOMAINS.remove();
  }
}
