package com.nbport.zgwl.auth;

import com.nbport.zgwl.entity.SysUserEntity;
import com.nbport.zgwl.utils.AdminSecurityManage;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * 本地模拟 SecurityManager。
 *
 * 保持与正式环境接近的方法形态：
 * securityManager.isSuperAdmin()
 */
@Component
public class SecurityManager {

    private static final Set<Long> SUPER_ADMIN_IDS = Set.of(1L);

    private final AdminSecurityManage adminSecurityManage;

    public SecurityManager(AdminSecurityManage adminSecurityManage) {
        this.adminSecurityManage = adminSecurityManage;
    }

    public boolean isSuperAdmin() {
        SysUserEntity currentUser = adminSecurityManage.getUser();
        return currentUser != null
                && currentUser.getId() != null
                && SUPER_ADMIN_IDS.contains(currentUser.getId());
    }
}
