package com.nursinghome.config;

import cn.dev33.satoken.stp.StpInterface;
import com.nursinghome.entity.User;
import com.nursinghome.mapper.UserMapper;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

@Component
public class SaTokenStpInterfaceImpl implements StpInterface {
    private final UserMapper userMapper;

    public SaTokenStpInterfaceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return Collections.emptyList();
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        User user = userMapper.findById(Long.valueOf(loginId.toString()));
        if (user == null) {
            return Collections.emptyList();
        }
        return Collections.singletonList(user.getRole());
    }
}
