package org.wcs.business.saToken;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.wcs.business.redis.SaTokenRedis;

import java.util.List;

/**
 * sa-token 权限验证接口实现类
 */
@Component
@RequiredArgsConstructor
public class StpInterfaceImpl implements StpInterface {

    // saToken缓存
    private final SaTokenRedis saTokenRedis;

    /**
     * 返回一个账号所拥有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        String userGroup = saTokenRedis.getUserGroup(loginId.toString());
        if(userGroup == null || userGroup.isEmpty()) {
            return List.of();
        }
        String[] userGroupPermission = saTokenRedis.getUserGroupPermission(userGroup);
        return List.of(userGroupPermission);
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return List.of();
    }
}
