package kr.co.accura.wtm.domain.user.dto;

import kr.co.accura.wtm.domain.user.entity.User;

import java.util.List;

public record UserDto(
        Long id,
        String employeeId,
        String email,
        String username,
        String fullName,
        String department,
        String discipline,
        String positionTitle,
        String location,
        String employmentType,
        Boolean isActive,
        List<String> roles
) {
    public static UserDto from(User user) {
        List<String> roleNames = user.getUserRoles().stream()
                .map(ur -> ur.getRole().getCode())
                .toList();
        return new UserDto(
                user.getId(),
                user.getEmployeeId(),
                user.getEmail(),
                user.getUsername(),
                user.getFullName(),
                user.getDepartment(),
                user.getDiscipline(),
                user.getPositionTitle(),
                user.getLocation(),
                user.getEmploymentType() != null ? user.getEmploymentType().name() : null,
                user.getIsActive(),
                roleNames
        );
    }
}
