package com.hitcommunications.servermanager.model; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.UpdateTimestamp; import java.sql.Timestamp; import java.util.UUID; @Entity @Table(name = "tab_users") @AllArgsConstructor @NoArgsConstructor @Getter @Setter @Builder public class Users { @Id @GeneratedValue(strategy = GenerationType.UUID) @Column(updatable = false, nullable = false) private UUID id; @Column(nullable = false, unique = true) private String username; @Column(nullable = false, unique = true, length = 100) private String email; @Column(nullable = false, length = 120) private String password; @Column(nullable = false, length = 30) private String firstName; @Column(nullable = false, length = 30) private String lastName; @CreationTimestamp @Column(nullable = false) private Timestamp createdAt; @UpdateTimestamp @Column(nullable = false) private Timestamp updatedAt; private Timestamp lastLogin; @PrePersist private void prePersist() { if (this.username == null) { this.username = generateUsername(); } } public String generateUsername() { String firstPart = this.firstName != null && this.firstName.length() >= 3 ? this.firstName.substring(0, 3) : (this.firstName != null ? this.firstName : ""); String secondPart = this.lastName != null && this.lastName.length() >= 3 ? this.lastName.substring(0, 3) : (this.lastName != null ? this.lastName : ""); this.username = firstPart + secondPart; return this.username.toLowerCase(); } }