content: package mflix.api.models;
  
  import com.fasterxml.jackson.annotation.JsonIgnore;
  import org.springframework.security.core.GrantedAuthority;
  import org.springframework.security.core.userdetails.UserDetails;
  
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Objects;
  
  public class UserPrincipal implements UserDetails {
    private Long id;
  
    private String name;
  
    private String username;
  
    @JsonIgnore private String email;
  
    @JsonIgnore private String password;
  
    private Collection<? extends GrantedAuthority> authorities;
  
    public UserPrincipal(
        Long id,
        String name,
        String username,
        String email,
        String password,
        Collection<? extends GrantedAuthority> authorities) {
      this.id = id;
      this.name = name;
      this.username = username;
      this.email = email;
      this.password = password;
      this.authorities = authorities;
    }
  
    public static UserPrincipal create(User user) {
      return new UserPrincipal(
          (long) 1,
          user.getName(),
          user.getEmail(),
          user.getEmail(),
          user.getHashedpw(),
          new ArrayList<>());
    }
  
    public Long getId() {
      return id;
    }
  
    public String getName() {
      return name;
    }
  
    public String getEmail() {
      return email;
    }
  
    @Override
    public String getUsername() {
      return username;
    }
  
    @Override
    public String getPassword() {
      return password;
    }
  
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
      return authorities;
    }
  
    @Override
    public boolean isAccountNonExpired() {
      return true;
    }
  
    @Override
    public boolean isAccountNonLocked() {
      return true;
    }
  
    @Override
    public boolean isCredentialsNonExpired() {
      return true;
    }
  
    @Override
    public boolean isEnabled() {
      return true;
    }
  
    @Override
    public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;
      UserPrincipal that = (UserPrincipal) o;
      return Objects.equals(id, that.id);
    }
  
    @Override
    public int hashCode() {
      return Objects.hash(id);
    }
  }
  