package com.base.orbit.domain.enity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.base.orbit.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date;
import java.util.List;


/**
 * 用户表(SysUser)实体类
 *
 * @author xj
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TableName(value = "sys_user")
@ApiModel("用户实体类")
public class SysUser extends BaseEntity implements Serializable {
    private static final long serialVersionUID = -40356785423868312L;

    @ApiModelProperty("用户编号")
    @TableId(type= IdType.AUTO)
    private Long userId;

    @ApiModelProperty("用户名称")
    @NotBlank(message = "用户名不能为空！")
    private String userName;

    @ApiModelProperty("昵称")
    @NotBlank(message = "昵称不能为空！")
    private String nickName;

    @ApiModelProperty("性别")
    @NotBlank(message = "性别不能为空！")
    private String sex;

    @ApiModelProperty("密码")
    @NotBlank(message = "密码不能为空！")
    private String passWord;

    @ApiModelProperty("帐号状态（0正常 1停用）")
    @NotBlank(message = "帐号状态不能为空！")
    private String status;

    @ApiModelProperty("邮箱")
    @NotBlank(message = "邮箱不能为空！")
    private String email;

    @ApiModelProperty("手机号")
    private String phoneNumber;

    @ApiModelProperty("头像")
    private String avatar;

    @ApiModelProperty("用户类型（0管理员，1普通用户）")
    private String userType;

    @ApiModelProperty("删除标志（0代表未删除，1代表已删除）")
    private Integer delFlag;

    @ApiModelProperty("最后登录ip")
    private String loginIp;

    @ApiModelProperty("最后登录时间")
    private Date loginDate;

    @ApiModelProperty("创建人")
    private String createBy;

    @ApiModelProperty("创建时间")
    private Date createTime;

    @ApiModelProperty("修改人")
    private String updateBy;

    @ApiModelProperty("修改时间")
    private Date updateTime;

    @ApiModelProperty("备注")
    private String remark;

    @ApiModelProperty("角色对象")
    @TableField(exist = false)
    private List<SysRole> roles;

    @ApiModelProperty("角色组")
    @TableField(exist = false)
    private Long[] roleIds;

    @ApiModelProperty("角色ID")
    @TableField(exist = false)
    private Long roleId;

    public SysUser(Long userId) {
        this.userId = userId;
    }

    //  判断是否为管理员
    public boolean isAdmin() {
        return isAdmin(this.userId);
    }


    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }

}