content: package com.pomodoro.app.model;
  
  import java.time.LocalDateTime;
  import java.util.Collection;
  import java.util.HashSet;
  import java.util.Set;
  
  import jakarta.persistence.Column;
  import jakarta.persistence.Entity;
  import jakarta.persistence.GeneratedValue;
  import jakarta.persistence.GenerationType;
  import jakarta.persistence.Id;
  import jakarta.persistence.OneToMany;
  import jakarta.persistence.Table;
  import jakarta.validation.constraints.Email;
  import jakarta.validation.constraints.NotBlank;
  import jakarta.validation.constraints.Size;
  
  import org.springframework.security.core.GrantedAuthority;
  import org.springframework.security.core.authority.SimpleGrantedAuthority;
  import org.springframework.security.core.userdetails.UserDetails;
  
  import lombok.AllArgsConstructor;
  import lombok.Builder;
  import lombok.Data;
  import lombok.NoArgsConstructor;
  import lombok.ToString;
  
  @Entity
  @Table(name = "users")
  @Data
  @Builder
  @NoArgsConstructor
  @AllArgsConstructor
  @ToString(exclude = "sessions")
  public class User implements UserDetails {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
  
      @NotBlank(message = "Username is required")
      @Size(min = 3, max = 50, message = "Username must be between 3 and 50 characters")
      @Column(unique = true, nullable = false)
      private String username;
  
      @NotBlank(message = "Email is required")
      @Email(message = "Email should be valid")
      @Column(unique = true, nullable = false)
      private String email;
  
      @NotBlank(message = "Password is required")
      @Column(nullable = false)
      private String password;
  
      @Column(name = "created_at")
      private LocalDateTime createdAt;
  
      @Column(name = "updated_at")
      private LocalDateTime updatedAt;
  
      @Column(name = "focus_duration")
      private Integer focusDuration = 25; // Default 25 minutes
  
      @Column(name = "break_duration")
      private Integer breakDuration = 5; // Default 5 minutes
  
      @Column(name = "long_break_duration")
      private Integer longBreakDuration = 15; // Default 15 minutes
  
      @Column(name = "pomodoros_until_long_break")
      private Integer pomodorosUntilLongBreak = 4; // Default 4 pomodoros
  
      @Column(name = "auto_start_breaks")
      private Boolean autoStartBreaks = false;
  
      @Column(name = "auto_start_pomodoros")
      private Boolean autoStartPomodoros = false;
  
      @Column(name = "daily_target")
      private Integer dailyTarget = 8; // Default 8 pomodoros
  
      @OneToMany(mappedBy = "user")
      private Set<PomodoroSession> sessions = new HashSet<>();
  
      // UserDetails implementation
      @Override
      public Collection<? extends GrantedAuthority> getAuthorities() {
          Set<GrantedAuthority> authorities = new HashSet<>();
          authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
          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;
      }
  }