package com.yaoyuan.jiscuss.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@Data
@Entity
@Table(name = "user")
public class User implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @NotBlank
    @Size(min = 3, max = 50)
    @Column(name = "username")
    private String username;

    @Size(max = 50)
    @Column(name = "realname")
    private String realname;

    @Email
    @Size(max = 100)
    @Column(name = "email")
    private String email;

    /** BCrypt-hashed password. Column length must be >= 68 (see V2 migration). Never serialized to JSON. */
    @JsonIgnore
    @Column(name = "password")
    private String password;

    @Column(name = "join_time")
    private Date joinTime;

    @Column(name = "age")
    private Integer age;

    @Pattern(regexp = "^(男|女|其他)?$")
    @Column(name = "gender")
    private String gender;

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

    @Size(max = 20)
    @Column(name = "phone")
    private String phone;

    @Column(name = "discussions_count")
    private Integer discussionsCount;

    @Column(name = "comments_count")
    private Integer commentsCount;

    @Column(name = "last_seen_time")
    private Date lastSeenTime;

    @Column(name = "flag")
    private Integer flag;

    @Column(name = "level")
    private Integer level;
}
