package com.sino.mci.admin.security;

import cn.dev33.satoken.stp.StpUtil;
import lombok.Data;

import java.util.List;

public class AuthContext {

    @Data
    public static class AuthUser {
        private Long userId;
        private String tenantCode;
        private String username;
        private List<String> roleCodes;
    }

    public static AuthUser get() {
        if (!StpUtil.isLogin()) {
            return null;
        }
        AuthUser user = new AuthUser();
        user.setUserId(StpUtil.getLoginIdAsLong());
        user.setTenantCode((String) StpUtil.getSession().get("tenantCode"));
        user.setUsername((String) StpUtil.getSession().get("username"));
        user.setRoleCodes((List<String>) StpUtil.getSession().get("roleCodes"));
        return user;
    }

    public static String currentTenantCode() {
        AuthUser user = get();
        return user == null ? null : user.getTenantCode();
    }
}
