/**
 * 
 */
package org.springblade.modules.auth.granter;

import org.springblade.modules.auth.provider.ITokenGranter;
import org.springblade.modules.auth.provider.TokenParameter;
import org.springblade.modules.system.entity.UserInfo;
import org.springblade.modules.system.service.IUserService;
import org.springframework.stereotype.Component;

import com.github.xiaoymin.knife4j.core.util.StrUtil;

import lombok.AllArgsConstructor;

/**
 * @author wookvn
 *
 */
@Component
@AllArgsConstructor
public class UserIdTokenGranter implements ITokenGranter {

	public static final String GRANT_TYPE = "userid";

	private final IUserService userService;
//	private final ITenantService tenantService;

	@Override
	public UserInfo grant(TokenParameter tokenParameter) {
//		String tenantId = tokenParameter.getArgs().getStr("tenantId");
		String userId = tokenParameter.getArgs().getStr("userId");
		UserInfo userInfo = null;
		if (StrUtil.isNotBlank(userId)) {
			// 根据不同用户类型调用对应的接口返回数据，用户可自行拓展
			userInfo = userService.userInfo(Long.valueOf(userId));
			// 获取租户信息
//			if(userInfo != null && userInfo.getUser() != null) {
//				Tenant tenant = tenantService.getByTenantId(userInfo.getUser().getTenantId());
//				if (TokenUtil.judgeTenant(tenant)) {
//					throw new ServiceException(TokenUtil.USER_HAS_NO_TENANT_PERMISSION);
//				}
//			}
		}
		return userInfo;
	}

}