package com.erp.user.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

import java.time.LocalDateTime;

/**
 * 用户实体类
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@TableName("users")
public class User {
    
    @TableId(type = IdType.AUTO)
    private Long id;
    
    private Long tenantId;
    private String username;
    private String email;
    private String phone;
    
    /**
     * 数据库密码字段（内部使用）
     */
    @TableField("password_hash")
    @JsonIgnore
    private String passwordHash;
    
    /**
     * 明文密码（用于API输入，JSON序列化时忽略）
     */
    @TableField(exist = false)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String password;
    
    private String realName;
    private Integer status;
    
    @TableField(exist = false)
    @JsonIgnore
    private Boolean superAdmin;
    
    @TableField(exist = false)
    private LocalDateTime lastLoginAt;
    
    @TableField(exist = false)
    private String lastLoginIp;
    
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
    private LocalDateTime deletedAt;
    
    /**
     * 判断用户是否启用
     */
    @JsonIgnore
    public boolean isEnabled() {
        return status != null && status == 1;
    }
}
