package com.inspect.system.base.domain;

import com.inspect.base.core.annotation.Excel;
import com.inspect.base.core.annotation.Excels;
import com.inspect.base.core.annotation.Excel.ColumnType;
import com.inspect.base.core.annotation.Excel.Type;
import com.inspect.base.core.web.domain.BaseEntity;
import com.inspect.base.core.xss.Xss;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

import lombok.Setter;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

@Setter
public class SysUser extends BaseEntity {
    private static final long serialVersionUID = 1L;
    @Excel(
            name = "用户序号",
            cellType = ColumnType.NUMERIC,
            prompt = "用户编号"
    )
    private Long userId;
    @Excel(
            name = "部门编号",
            type = Type.IMPORT
    )
    private Long deptId;
    @Excel(
            name = "登录名称"
    )
    private String userName;
    @Excel(
            name = "用户名称"
    )
    private String nickName;
    @Excel(
            name = "用户邮箱"
    )
    private String email;
    @Excel(
            name = "手机号码"
    )
    private String phonenumber;
    @Excel(
            name = "用户性别",
            readConverterExp = "0=男,1=女,2=未知"
    )
    private String sex;
    private String avatar;
    private String password;
    @Excel(
            name = "帐号状态",
            readConverterExp = "0=正常,1=停用"
    )
    private String status;
    private String delFlag;
    @Excel(
            name = "最后登录IP",
            type = Type.EXPORT
    )
    private String loginIp;
    @Excel(
            name = "最后登录时间",
            width = 30.0D,
            dateFormat = "yyyy-MM-dd HH:mm:ss",
            type = Type.EXPORT
    )
    private Date loginDate;
    @Excels({@Excel(
            name = "部门名称",
            targetAttr = "deptName",
            type = Type.EXPORT
    ), @Excel(
            name = "部门负责人",
            targetAttr = "leader",
            type = Type.EXPORT
    )})
    private SysDept dept;
    private List<SysRole> roles;
    private Long[] roleIds;
    private Long[] postIds;
    private Long roleId;
    private Date passUpdateTime;
    private String aollowIp;

    public String getAollowIp() {
        return this.aollowIp;
    }

    public Date getPassUpdateTime() {
        return this.passUpdateTime;
    }

    public SysUser() {
    }

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

    public Long getUserId() {
        return this.userId;
    }

    public boolean isAdmin() {
        return isAdmin(this.userId);
    }

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

    public Long getDeptId() {
        return this.deptId;
    }

    @Xss(
            message = "用户昵称不能包含脚本字符"
    )
    @Size(
            min = 0,
            max = 30,
            message = "用户昵称长度不能超过30个字符"
    )
    public String getNickName() {
        return this.nickName;
    }

    @Xss(
            message = "用户账号不能包含脚本字符"
    )
    @NotBlank(
            message = "用户账号不能为空"
    )
    @Size(
            min = 0,
            max = 30,
            message = "用户账号长度不能超过30个字符"
    )
    public String getUserName() {
        return this.userName;
    }

    @Email(
            message = "邮箱格式不正确"
    )
    @Size(
            min = 0,
            max = 50,
            message = "邮箱长度不能超过50个字符"
    )
    public String getEmail() {
        return this.email;
    }

    @Size(
            min = 0,
            max = 11,
            message = "手机号码长度不能超过11个字符"
    )
    public String getPhonenumber() {
        return this.phonenumber;
    }

    public String getSex() {
        return this.sex;
    }

    public String getAvatar() {
        return this.avatar;
    }

    @JsonProperty
    public String getPassword() {
        return this.password;
    }

    public String getStatus() {
        return this.status;
    }

    public String getDelFlag() {
        return this.delFlag;
    }

    public String getLoginIp() {
        return this.loginIp;
    }

    public Date getLoginDate() {
        return this.loginDate;
    }

    public SysDept getDept() {
        return this.dept;
    }

    public List<SysRole> getRoles() {
        return this.roles;
    }

    public Long[] getRoleIds() {
        return this.roleIds;
    }

    public Long[] getPostIds() {
        return this.postIds;
    }

    public Long getRoleId() {
        return this.roleId;
    }

    @Override
    public String toString() {
        return "SysUser{" +
                "userId=" + userId +
                ", deptId=" + deptId +
                ", userName='" + userName + '\'' +
                ", nickName='" + nickName + '\'' +
                ", email='" + email + '\'' +
                ", phonenumber='" + phonenumber + '\'' +
                ", sex='" + sex + '\'' +
                ", avatar='" + avatar + '\'' +
                ", password='" + password + '\'' +
                ", status='" + status + '\'' +
                ", delFlag='" + delFlag + '\'' +
                ", loginIp='" + loginIp + '\'' +
                ", loginDate=" + loginDate +
                ", dept=" + dept +
                ", roles=" + roles +
                ", roleIds=" + Arrays.toString(roleIds) +
                ", postIds=" + Arrays.toString(postIds) +
                ", roleId=" + roleId +
                ", passUpdateTime=" + passUpdateTime +
                ", aollowIp='" + aollowIp + '\'' +
                '}';
    }
}
