package com.yida.data.common.core.entity.system;

import com.baomidou.mybatisplus.annotation.FieldFill;
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.fasterxml.jackson.annotation.JsonFormat;
import com.yida.data.common.core.annotation.IsMobile;
import com.yida.data.common.core.entity.system.enums.DeptTypeEnum;
import com.yida.data.common.core.entity.system.enums.RoleEnum;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * @author MrBird
 */
@Data
@TableName("t_user")
public class SystemUser implements Serializable {

    /**
     * 用户状态：有效
     */
    public static final String STATUS_VALID = "1";
    /**
     * 用户状态：锁定
     */
    public static final String STATUS_LOCK = "0";
    /**
     * 默认头像
     */
    public static final String DEFAULT_AVATAR = "default.jpg";
    /**
     * 默认密码
     */
    public static final String DEFAULT_PASSWORD = "zbz@2021";
    /**
     * 性别男
     */
    public static final String SEX_MALE = "0";
    /**
     * 性别女
     */
    public static final String SEX_FEMALE = "1";
    /**
     * 性别保密
     */
    public static final String SEX_UNKNOW = "2";
    private static final long serialVersionUID = -4352868070794165001L;
    /**
     * 用户 ID
     */
    @TableId(value = "USER_ID", type = IdType.AUTO)
    private Long userId;

    private String nickname;

    /**
     * 用户名
     */
    @TableField("USERNAME")
    @Size(min = 4, max = 20, message = "{range}")
    private String username;

    /**
     * 密码
     */
    @TableField("PASSWORD")
    private String password;

    /**
     * 部门 ID
     */
    @TableField("DEPT_ID")
    private Long deptId;

    /**
     * 邮箱
     */
    @TableField("EMAIL")
    @Size(max = 50, message = "{noMoreThan}")
    @Email(message = "{email}")
    private String email;

    /**
     * 联系电话
     */
    @TableField("MOBILE")
    @IsMobile(message = "{mobile}")
    private String mobile;

    /**
     * 状态 0锁定 1有效
     */
    @TableField("STATUS")
    @NotBlank(message = "{required}")
    private String status;

    /**
     * 创建时间
     */
    @TableField(value = "CREATE_TIME", fill = FieldFill.INSERT)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createDate;

    /**
     * 修改时间
     */
    @TableField(value = "MODIFY_TIME", fill = FieldFill.UPDATE)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateDate;

    /**
     * 最近访问时间
     */
    @TableField("LAST_LOGIN_TIME")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime lastLoginTime;

    /**
     * 性别 0男 1女 2 保密
     */
    @TableField("SSEX")
    @NotBlank(message = "{required}")
    private String sex;

    /**
     * 头像
     */
    @TableField("AVATAR")
    private String avatar;

    /**
     * 描述
     */
    @TableField("DESCRIPTION")
    @Size(max = 100, message = "{noMoreThan}")
    private String description;

    /**
     * 0-微信来源注册，1-pc来源注册，2-app来源注册
     */
    private Integer userOrigin;

    /**
     * 教师的微信id
     */
    private String teacherWxId;

    private String openId;

    /**
     * 代理商部门id(角色为代理商相关时存在)
     */
    @TableField(exist = false)
    private Long agentId;

    /**
     * 部门名称
     */
    @TableField(exist = false)
    private String deptName;

    /**
     * 部门类型 {@link DeptTypeEnum}
     */
    @TableField(exist = false)
    private Integer deptType;

    @TableField(exist = false)
    private String createTimeFrom;
    @TableField(exist = false)
    private String createTimeTo;
    /**
     * 角色 ID
     */
    @NotBlank(message = "{required}")
    @TableField(exist = false)
    private String roleId;

    @TableField(exist = false)
    private String roleName;

    /**
     * 角色标识
     */
    @TableField(exist = false)
    private String rolePerms;

    @TableField(exist = false)
    private String deptIds;

    @TableField(exist = false)
    private Long identityId;

    @TableField(exist = false)
    @ApiModelProperty("用户类型，0-家长，1-教师")
    private Integer userType;

    @TableField(exist = false)
    @ApiModelProperty("易达app用户id")
    private String yidaAppUserId;


    /**
     * 角色类型集合 {@link RoleEnum}
     */
    @TableField(exist = false)
    private List<Integer> roleTypeList;

    /**
     * 创建人id
     */
    @TableField("create_id")
    private Long createId;

    /**
     * 创建人部门id
     */
    @TableField("create_dept_id")
    private Long createDeptId;

    /**
     * 主部门id(学校或教育局部门id)
     */
    @TableField("main_dept_id")
    private Long mainDeptId;

    /**
     * 主角色标识
     */
    @TableField(exist = false)
    private String mainRolePerms;

    private transient EduUserLogo userLogo;

    /**
     * 学校性质：0幼儿园，1小学，2中学，3九年一贯，4十二年一贯，5：高校
     */
    private transient Integer schoolNature;
}
