package com.gnx.telemedicine.model;

import com.gnx.telemedicine.model.enums.Role;
import com.gnx.telemedicine.model.enums.UserStatus;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDate;
import java.util.UUID;

@Getter
@Setter
@Entity
@Table(name = "users")
public class UserModel {
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.UUID)
    private UUID id;

    @Column(name = "email")
    private String email;

    @Column(name = "password")
    private String password;

    @Enumerated(EnumType.STRING)
    @Column(name = "role")
    private Role role;

    @Column(name = "first_name")
    private String firstName;

    @Column(name = "last_name")
    private String lastName;

    @Column(name = "phone_number")
    private String phoneNumber;

    @Column(name = "is_active")
    private Boolean isActive;

    @CreationTimestamp
    @Column(name = "created_at")
    private LocalDate createdAt;

    @UpdateTimestamp
    @Column(name = "updated_at")
    private LocalDate updatedAt;

    @Column(name = "is_online")
    private Boolean isOnline = false;

    @Enumerated(EnumType.STRING)
    @Column(name = "user_status")
    private UserStatus userStatus = UserStatus.OFFLINE;

    @Column(name = "last_seen")
    private java.time.LocalDateTime lastSeen;

    @Column(name = "avatar_url", length = 500)
    private String avatarUrl;

    @Column(name = "failed_login_attempts")
    private Integer failedLoginAttempts = 0;

    @Column(name = "account_locked_until")
    private java.time.Instant accountLockedUntil;

    @Column(name = "last_failed_login")
    private java.time.Instant lastFailedLogin;

    @Column(name = "password_reset_token")
    private String passwordResetToken;

    @Column(name = "password_reset_token_expiry")
    private java.time.Instant passwordResetTokenExpiry;
    
    @Column(name = "password_changed_at")
    private java.time.Instant passwordChangedAt;
    
    @Column(name = "password_expires_at")
    private java.time.Instant passwordExpiresAt;
    
    @Column(name = "password_expiration_days")
    private Integer passwordExpirationDays = 90; // Default: 90 days
    
    @Column(name = "password_history_count")
    private Integer passwordHistoryCount = 5; // Default: keep last 5 passwords
}