// Path: spat-services/src/main/java/com/pcalouche/spat/entity/User.java
// @Entity
// @Table(name = "users")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class User implements UserDetails {
//     @Id
//     @GeneratedValue(strategy = GenerationType.IDENTITY)
//     private Integer id;
//     @NotBlank
//     @Column(unique = true, nullable = false)
//     private String username;
//     @NotBlank
//     @Column(nullable = false)
//     private String password;
//     @Builder.Default
//     private boolean accountNonExpired = true;
//     @Builder.Default
//     private boolean accountNonLocked = true;
//     @Builder.Default
//     private boolean credentialsNonExpired = true;
//     @Builder.Default
//     private boolean enabled = true;
//     @ManyToMany(fetch = FetchType.EAGER)
//     @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
//     @Builder.Default
//     private Set<Role> roles = new HashSet<>();
//     @Transient
//     @Setter(AccessLevel.NONE)
//     private Set<SimpleGrantedAuthority> authorities;
// 
//     @Override
//     public Set<SimpleGrantedAuthority> getAuthorities() {
//         if (authorities == null) {
//             authorities = new HashSet<>();
//             if (roles != null) {
//                 for (Role role : roles) {
//                     authorities.add(new SimpleGrantedAuthority(role.getName()));
//                 }
//             }
//         }
//         return authorities;
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) {
//             return true;
//         }
//         if (!(o instanceof User)) {
//             return false;
//         }
//         User castedObj = (User) o;
//         return Objects.equals(username, castedObj.getUsername());
//     }
// 
//     @Override
//     public int hashCode() {
//         return Objects.hash(username);
//     }
// }


import com.fasterxml.jackson.annotation.JsonProperty;
import com.pcalouche.spat.entity.User;
import lombok.*;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
package com.pcalouche.spat.api.dto;



@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UserDto {
    @EqualsAndHashCode.Exclude
    private Integer id;
    private String username;
    @Builder.Default
    private boolean accountNonExpired = true;
    @Builder.Default
    private boolean accountNonLocked = true;
    @Builder.Default
    private boolean credentialsNonExpired = true;
    @Builder.Default
    private boolean enabled = true;
    @JsonProperty("roles")
    @Builder.Default
    private Set<RoleDto> roleDtos = new HashSet<>();

// Path: spat-services/src/main/java/com/pcalouche/spat/entity/User.java
// @Entity
// @Table(name = "users")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class User implements UserDetails {
//     @Id
//     @GeneratedValue(strategy = GenerationType.IDENTITY)
//     private Integer id;
//     @NotBlank
//     @Column(unique = true, nullable = false)
//     private String username;
//     @NotBlank
//     @Column(nullable = false)
//     private String password;
//     @Builder.Default
//     private boolean accountNonExpired = true;
//     @Builder.Default
//     private boolean accountNonLocked = true;
//     @Builder.Default
//     private boolean credentialsNonExpired = true;
//     @Builder.Default
//     private boolean enabled = true;
//     @ManyToMany(fetch = FetchType.EAGER)
//     @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
//     @Builder.Default
//     private Set<Role> roles = new HashSet<>();
//     @Transient
//     @Setter(AccessLevel.NONE)
//     private Set<SimpleGrantedAuthority> authorities;
// 
//     @Override
//     public Set<SimpleGrantedAuthority> getAuthorities() {
//         if (authorities == null) {
//             authorities = new HashSet<>();
//             if (roles != null) {
//                 for (Role role : roles) {
//                     authorities.add(new SimpleGrantedAuthority(role.getName()));
//                 }
//             }
//         }
//         return authorities;
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) {
//             return true;
//         }
//         if (!(o instanceof User)) {
//             return false;
//         }
//         User castedObj = (User) o;
//         return Objects.equals(username, castedObj.getUsername());
//     }
// 
//     @Override
//     public int hashCode() {
//         return Objects.hash(username);
//     }
// }


// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/UserDto.java
import com.fasterxml.jackson.annotation.JsonProperty;
import com.pcalouche.spat.entity.User;
import lombok.*;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

package com.pcalouche.spat.api.dto;



@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UserDto {
    @EqualsAndHashCode.Exclude
    private Integer id;
    private String username;
    @Builder.Default
    private boolean accountNonExpired = true;
    @Builder.Default
    private boolean accountNonLocked = true;
    @Builder.Default
    private boolean credentialsNonExpired = true;
    @Builder.Default
    private boolean enabled = true;
    @JsonProperty("roles")
    @Builder.Default
    private Set<RoleDto> roleDtos = new HashSet<>();

    public static UserDto map(User user) {