package ru.kayashov.bar.model.entity;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

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

@Getter
@RequiredArgsConstructor
public enum UserRole {

    USER(Set.of("user")),
    BARMEN(Set.of("user", "barmen")),
    ADMIN(Set.of("user", "barmen", "admin")),
    ADMIN_NOT_BARMEN(Set.of("user", "admin"));

    private final Set<String> authorities;

    public Set<GrantedAuthority> getAuthorities() {
        return authorities.stream()
                .map(SimpleGrantedAuthority::new)
                .collect(Collectors.toSet());
    }
}
