package com.psg.dlsysinfo.dl_sysinfo_server.entity;

import jakarta.persistence.*;
import java.time.LocalDateTime;

@Entity
@Table(name = "users")
public class UserAuth {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @Column(name = "username", nullable = false, length = 50)
    private String username;

    @Column(name = "password_hash", nullable = false, length = 60)
    private String passwordHash;

    @ManyToOne
    @JoinColumn(name = "clientId", nullable = false)
    private Client client;

    @Column(nullable = false)
    private String role;

    @Column(name = "created_at", nullable = false)
    private LocalDateTime createdAt;

    @Column(name = "password_changed_at")
    private LocalDateTime passwordChangedAt;

    @Column(name = "display_name_hash", length = 100)
    private String displayNameHash;

    @Column(name = "first_name_hash")
    private String firstNameHash;

    @Column(name = "last_name_hash")
    private String lastNameHash;


    @Column(name = "email_hash", length = 256)
    private String emailHash;

    @Column(nullable = false)
    private boolean enabled = true;




    // Getters and Setters

    public Long getId() { return id; }

    public void setId(Long id) { this.id = id; }

    public String getUsername() { return username; }

    public void setUsername(String username) { this.username = username; }

    public String getPasswordHash() { return passwordHash; }

    public void setPasswordHash(String passwordHash) { this.passwordHash = passwordHash; }

    public Client getClient() { return client; }

    public void setClient(Client client) { this.client = client; }

    public String getRole() { return role; }

    public void setRole(String role) { this.role = role; }

    public LocalDateTime getCreatedAt() { return createdAt; }

    public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }

    public LocalDateTime getPasswordChangedAt() {
        return passwordChangedAt;
    }

    public void setPasswordChangedAt(LocalDateTime passwordChangedAt) {
        this.passwordChangedAt = passwordChangedAt;
    }

    public String getDisplayNameHash() {return displayNameHash; }

    public void setDisplayNameHash(String displayNameHash) {this.displayNameHash = displayNameHash; }

    public String getEmailHash() { return emailHash; }

    public void setEmailHash(String emailHash) { this.emailHash = emailHash; }
    public String getFirstNameHash() {
        return firstNameHash;
    }

    public void setFirstNameHash(String firstNameHash) {
        this.firstNameHash = firstNameHash;
    }

    public String getLastNameHash() {
        return lastNameHash;
    }

    public void setLastNameHash(String lastNameHash) {
        this.lastNameHash = lastNameHash;
    }
    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }
    public String getClientNameEncrypted() {
        return client != null ? client.getClientNameEncrypted() : null;
    }

}
