/**
 * Copyright 2018-2020 stylefeng & fengshuonan (sn93@qq.com)
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.inkasso.adapter.web;


import com.inkasso.adapter.bean.AbstractUser;
import com.inkasso.adapter.constance.AuthConstance;

import javax.servlet.http.HttpServletRequest;

/**
 * 登录信息
 *
 * @author zc
 * @date 2021-03-18
 */

public class LoginContext {

  private static final String NAMES_DELIMETER = ",";


  /**
   */
  public static String getToken() {
    HttpServletRequest request = HttpContext.getRequest();
    String token = request.getHeader(AuthConstance.X_AUTH_ACCESS);
    return token;
  }

  /**
   * 获取用户id
   *
   * @return
   */
  public static Long getUserId() {
    AbstractUser baseUser = LoginUserHolder.get();
    if (baseUser != null) {
      return baseUser.getId();
    }
    return null;
  }

  /**
   * 获取租户id
   *
   * @return
   */
  public static Long getTenantId() {
    AbstractUser baseUser = LoginUserHolder.get();
    if (baseUser != null) {
      return baseUser.getTenantId();
    }
    return null;
  }

  /**
   * 获得当前登陆的用户
   *
   * @return
   */
  public static AbstractUser getCurrentUser() {
    AbstractUser baseUser = LoginUserHolder.get();
    return baseUser;
  }


}
