content: package com.taskmanager.taskmanager.entity;
  
  import io.micrometer.common.lang.NonNull;
  import jakarta.persistence.*;
  import jakarta.validation.constraints.Email;
  import jakarta.validation.constraints.NotBlank;
  import jakarta.validation.constraints.Size;
  import lombok.AllArgsConstructor;
  import lombok.Getter;
  import lombok.NoArgsConstructor;
  import lombok.Setter;
  
  import java.time.LocalDateTime;
  import java.util.List;
  
  @Getter
  @Setter
  @NoArgsConstructor
  @AllArgsConstructor
  @Entity
  @Table(name = "users")
  public class User {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id")
      private Long id;
      
      @Size(max = 20, message = "username cannot exceed 20 characters.")
      @Column(name = "username")
      private String username;
  
      @NonNull
      @NotBlank(message = "Email cannot be blank!")
      @Email(message = "Email should be valid.")
      @Size(max = 100, message = "Email cannot exceed 100 characters.")
      @Column(name = "email", nullable = false, unique = true, length = 100)
      private String email;
  
      @Column(name = "password_hash", length = 255)
      private String passwordHash;
  
      @Column(name = "created_at", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
      private LocalDateTime createdAt;
  
      @Column(name = "updated_at", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
      private LocalDateTime updatedAt;
  
      @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
      private List<Task> tasks;
  
      @OneToOne(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
      private UserSettings userSettings;
  
      @PrePersist
      protected void onCreate() {
          this.createdAt = LocalDateTime.now();
          if (this.userSettings == null) {
              UserSettings defaultSettings = new UserSettings();
              defaultSettings.setUser(this);
              this.userSettings = defaultSettings;
          }
      }
  
      @PreUpdate
      protected void onUpdate() {
          this.updatedAt = LocalDateTime.now();
      }
  }
  