package cn.minbb.iot.model;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;

@Entity
@Table(name = "user")
@NoArgsConstructor
public class User implements Serializable {

    @Getter
    @Setter
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false, columnDefinition = "INT COMMENT '用户实体ID'")
    private Long id;

    @Getter
    @Setter
    @Column(name = "username", nullable = false, columnDefinition = "VARCHAR(64) COMMENT '用户名'")
    private String username;

    @Getter
    @Setter
    @Column(name = "password", nullable = false, columnDefinition = "VARCHAR(64) COMMENT '密码'")
    private String password;

    @Getter
    @Setter
    @Column(name = "name", columnDefinition = "VARCHAR(64) COMMENT '姓名'")
    private String name;

    @Getter
    @Setter
    @Column(name = "avatar", columnDefinition = "VARCHAR(255) COMMENT '头像'")
    private String avatar;

    @Getter
    @Setter
    @Column(name = "phone", columnDefinition = "VARCHAR(16) COMMENT '手机号'")
    private String phone;

    @Getter
    @Setter
    @Column(name = "created_at", columnDefinition = "DATETIME COMMENT '创建时间'")
    @CreationTimestamp
    private Date createdAt;

    @Getter
    @Setter
    @Column(name = "updated_at", columnDefinition = "DATETIME COMMENT '更新时间'")
    @UpdateTimestamp
    private Date updatedAt;

    @Version
    @Column(name = "version", columnDefinition = "BIGINT COMMENT '版本号'")
    public Long version;

    public User(@NotNull String username, @NotNull String password) {
        this.username = username;
        this.password = password;
    }
}
