package com.mvrent.carrental.web;

import com.mvrent.carrental.model.Permission;
import com.mvrent.carrental.model.User;

import java.util.List;

public record StaffDto(
        Long id,
        String username,
        String fullName,
        String email,
        String phone,
        String role,
        boolean enabled,
        List<String> permissions
) {
    public static StaffDto from(User u) {
        return new StaffDto(
                u.getId(),
                u.getUsername(),
                u.getFullName(),
                u.getEmail(),
                u.getPhone(),
                u.getRole() != null ? u.getRole().name() : null,
                u.isEnabled(),
                u.getPermissions() != null ? u.getPermissions().stream().map(Permission::name).sorted().toList() : List.of()
        );
    }
}
