content: package com.example.demo.models;
  
  import java.time.LocalDateTime;
  
  import jakarta.persistence.Column;
  import jakarta.persistence.EmbeddedId;
  import jakarta.persistence.Entity;
  import jakarta.persistence.EnumType;
  import jakarta.persistence.Enumerated;
  import jakarta.persistence.Table;
  
  import org.springframework.security.crypto.password.PasswordEncoder;
  
  import org.hibernate.annotations.CreationTimestamp;
  import org.hibernate.annotations.UpdateTimestamp;
  
  import static com.example.demo.models.Role.ROLE_ADMIN;
  
  @Entity
  @Table(name = "users")
  public class User {
      @EmbeddedId
      private UserId id;
  
      @Column(name = "email")
      private String email;
  
      @Column(name = "name")
      private String name;
  
      @Column(name = "password")
      private String encodedPassword;
  
      @Column(name = "role")
      @Enumerated(EnumType.STRING)
      private Role role;
  
      @CreationTimestamp
      private LocalDateTime createdAt;
  
      @UpdateTimestamp
      private LocalDateTime updatedAt;
  
      private User() {
      }
  
      public User(UserId id, String email, String name, Role role) {
          this.id = id;
          this.email = email;
          this.name = name;
          this.role = role;
      }
  
      public void changePassword(String password,
                                 PasswordEncoder passwordEncoder) {
          this.encodedPassword = passwordEncoder.encode(password);
      }
  
      public UserId id() {
          return id;
      }
  
      public String name() {
          return name;
      }
  
      public String email() {
          return email;
      }
  
      public Role role() {
          return role;
      }
  
      public boolean isAdmin() {
          return role.equals(ROLE_ADMIN);
      }
  }
  