content: package org.ecomm.ecommgateway.persistence.entity;
  
  import com.fasterxml.jackson.annotation.JsonManagedReference;
  import jakarta.persistence.*;
  import java.util.Collection;
  import java.util.List;
  import lombok.*;
  import org.springframework.security.core.GrantedAuthority;
  import org.springframework.security.core.authority.SimpleGrantedAuthority;
  import org.springframework.security.core.userdetails.UserDetails;
  
  @Entity
  @Table(name = "users")
  @Getter
  @Setter
  @Builder
  @NoArgsConstructor
  @AllArgsConstructor
  public class UserCredentials implements UserDetails {
  
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    int id;
  
    @Column(name = "first_name")
    String firstName;
  
    @Column(name = "last_name")
    String lastName;
  
    String email;
  
    @Column(name = "passwd")
    String password;
  
    @Enumerated(EnumType.STRING)
    UserStatus status;
  
    @JsonManagedReference
    @OneToOne(mappedBy = "user", cascade = CascadeType.ALL)
    EUserRole role;
  
    String subject;
  
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
      return List.of(new SimpleGrantedAuthority(role.getRole().name()));
    }
  
    @Override
    public String getPassword() {
      return password;
    }
  
    @Override
    public String getUsername() {
      return email;
    }
  
    @Override
    public boolean isAccountNonExpired() {
      return true;
    }
  
    @Override
    public boolean isAccountNonLocked() {
      return true;
    }
  
    @Override
    public boolean isCredentialsNonExpired() {
      return true;
    }
  
    @Override
    public boolean isEnabled() {
      return true;
    }
  }
  