package application.core.model;

import application.core.utils.enums.RoleType;
import lombok.*;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

@Entity
@Table(name = "user")
@ToString
@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Builder
public class User implements Serializable {
    private static final String DEFAULT_STRING = "N/A";

    public User(String username, String password, RoleType role) {
        this.username = username;
        this.password = password;
        this.role = role;
    }

    @Id
    @Column(name = "Username", length = 60, unique = true, nullable = false)
    private String username;

    @Column(name = "Password", length = 30, nullable = false)
    private String password;

    @Column(name = "Role", nullable = false)
    private RoleType role;

    // Could do: change to FetchType.LAZY
    @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    private UserDetails userInfo;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
    private List<Document> documents;
}

@@ -399,176 +399,8 @@
 %22;%0A%0A
-    public User(String username, String password, RoleType role) %7B%0A        this.username = username;%0A        this.password = password;%0A        this.role = role;%0A    %7D%0A%0A
     
@@ -671,24 +671,78 @@
 Type role;%0A%0A
+    //TODO fix this. JPA repo crashes when find.all()%0A
     // Could
@@ -771,16 +771,18 @@
 pe.LAZY%0A
+//
     @One
@@ -839,16 +839,18 @@
 pe.ALL)%0A
+//
     priv
@@ -876,16 +876,133 @@
 rInfo;%0A%0A
+//     TODO fix this. userRepo.finAll() java.sql.SQLSyntaxErrorException: Table 'cwmd_db.drdocument' doesn't exist%0A//
     @One
@@ -1052,16 +1052,18 @@
 %22user%22)%0A
+//
     priv

comment buggy code