package cn.edu.whu.boot.user.services.impl;

import cn.edu.whu.boot.user.entities.Permission;
import cn.edu.whu.boot.user.mapper.PermissionMapper;
import cn.edu.whu.boot.user.services.PermissionService;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class PermissionServiceImpl implements PermissionService {

    private final PermissionMapper permissionMapper;

    public PermissionServiceImpl(PermissionMapper permissionMapper) {
        this.permissionMapper = permissionMapper;
    }

    @Override
    public Set<String> findByIdIn(List<Integer> permissionIds) {
        return permissionMapper
                .findByIdIn(permissionIds)
                .stream()
                .map(Permission::getDescription)
                .collect(Collectors.toSet());
    }

    @Override
    public Set<String> findAllDescriptions() {
        return new HashSet<>(permissionMapper.findAllDescriptions());
    }

    @Override
    public String findDescriptionById(int id) {
        return permissionMapper.findDescriptionById(id);
    }

    @Override
    public Set<String> findByRole(int roleId) {
        return new HashSet<>(permissionMapper.findDescriptionsByRole(roleId));
    }
}