package com.mzh.library.entity;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class User {
    private static final DateTimeFormatter DISPLAY_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");

    private long id;
    private String username;
    private String passwordHash;
    private String displayName;
    private Role role;
    private boolean active;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;

    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 String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    public Role getRole() {
        return role;
    }

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

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

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

    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }

    public String getActiveStatusCode() {
        return active ? "active" : "inactive";
    }

    public String getActiveStatusName() {
        return active ? "启用" : "停用";
    }

    public String getCreatedAtText() {
        return format(createdAt);
    }

    public String getUpdatedAtText() {
        return format(updatedAt);
    }

    private String format(LocalDateTime value) {
        return value == null ? "" : DISPLAY_FORMAT.format(value);
    }
}
