package ie.gmit.sw.models;

import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.Index;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.*;


@NodeEntity
public class User implements UserDetails {

    @GraphId
    private Long id;

    @Index(unique = true)
    //private String email;
    private String username;
    private String password;
    //private boolean enabled;

    @Relationship(type = "HAS_ROLE", direction = Relationship.OUTGOING)
    private List<Role> roles;

    public User() {
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
//    public User(Long id, String email, String username, String password, boolean enabled, Set<Role> authorities) {
//        this.id = id;
//        this.username = username;
//        this.password = password;
//        this.email = email;
//        this.enabled = enabled;
//        this.authorities = authorities;
//    }

    public User(String email, String username, String password) {
        this.username = username;
        this.password = password;
        //this.email = email;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }



    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

//    public String getEmail() {
//        return email;
//    }
//
//    public void setEmail(String email) {
//        this.email = email;
//    }

//    public boolean isEnabled() {
//        return enabled;
//    }
//
//    public void setEnabled(boolean enabled) {
//        this.enabled = enabled;
//    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> auths = new ArrayList<>();
        List<Role> roles = this.getRoles();
        for (Role role : roles) {
            auths.add(new SimpleGrantedAuthority(role.getName()));
        }
        return auths;
    }

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }
}
@@ -191,16 +191,79 @@
 onship;%0A
+import org.springframework.beans.factory.annotation.Autowired;%0A
 import o
@@ -532,17 +532,16 @@
 tails %7B%0A
-%0A
     @Gra
@@ -566,17 +566,16 @@
 ong id;%0A
-%0A
     @Ind
@@ -596,36 +596,8 @@
 ue)%0A
-    //private String email;%0A
     
@@ -654,18 +654,16 @@
 rd;%0A    
-//
 private 
@@ -679,16 +679,135 @@
 nabled;%0A
+    private boolean accountNonExpired;%0A    private boolean accountNonLocked;%0A    private boolean credentialsNonExpired;
 %0A    @Re
@@ -933,410 +933,8 @@
  %7D%0A%0A
-    @Override%0A    public boolean isEnabled() %7B%0A        return true;%0A    %7D%0A//    public User(Long id, String email, String username, String password, boolean enabled, Set%3CRole%3E authorities) %7B%0A//        this.id = id;%0A//        this.username = username;%0A//        this.password = password;%0A//        this.email = email;%0A//        this.enabled = enabled;%0A//        this.authorities = authorities;%0A//    %7D%0A%0A
     
@@ -1280,18 +1280,16 @@
 %0A    %7D%0A%0A
-%0A%0A
     publ
@@ -1526,321 +1526,8 @@
  %7D%0A%0A
-//    public String getEmail() %7B%0A//        return email;%0A//    %7D%0A//%0A//    public void setEmail(String email) %7B%0A//        this.email = email;%0A//    %7D%0A%0A//    public boolean isEnabled() %7B%0A//        return enabled;%0A//    %7D%0A//%0A//    public void setEnabled(boolean enabled) %7B%0A//        this.enabled = enabled;%0A//    %7D%0A%0A
     
@@ -1983,32 +1983,583 @@
 = roles;%0A    %7D%0A%0A
+    public void setEnabled(boolean enabled) %7B%0A        this.enabled = enabled;%0A    %7D%0A%0A    public void setAccountNonExpired(boolean accountNonExpired) %7B%0A        this.accountNonExpired = accountNonExpired;%0A    %7D%0A%0A    public void setAccountNonLocked(boolean accountNonLocked) %7B%0A        this.accountNonLocked = accountNonLocked;%0A    %7D%0A%0A    public void setCredentialsNonExpired(boolean credentialsNonExpired) %7B%0A        this.credentialsNonExpired = credentialsNonExpired;%0A    %7D%0A%0A    @Autowired%0A    public boolean isEnabled() %7B%0A        return enabled;%0A    %7D%0A%0A
     @Override%0A  
@@ -2606,36 +2606,49 @@
 %0A        return 
-true
+accountNonExpired
 ;%0A    %7D%0A%0A    @Ov
@@ -2703,36 +2703,48 @@
 %0A        return 
-true
+accountNonLocked
 ;%0A    %7D%0A%0A    @Ov
@@ -2812,20 +2812,37 @@
  return 
-true
+credentialsNonExpired
 ;%0A    %7D%0A

update user bean class, suiting to userdetail in spring security