package com.qmth.sop.business.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qmth.sop.common.base.BaseEntity;
import com.qmth.sop.common.enums.GenderEnum;
import com.qmth.sop.common.enums.RtzfSyncStatusEnum;
import com.qmth.sop.common.enums.UserSourceEnum;
import com.qmth.sop.common.util.Base64Util;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * <p>
 * 用户表
 * </p>
 *
 * @author wangliang
 * @since 2023-07-17
 */
@ApiModel(value = "SysUser对象", description = "用户表")
public class SysUser extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "用户名")
    @NotBlank(message = "请输入登录名")
    @Length(message = "登录名不能超过{max}个字符", max = 30)
    private String loginName;

    @ApiModelProperty(value = "姓名")
    @Length(message = "姓名不能超过{max}个字符", max = 32)
    private String realName;

    @ApiModelProperty(value = "工号")
    private String code;

    @ApiModelProperty(value = "密码")
    private String password;

    @ApiModelProperty(value = "新密码")
    @TableField(exist = false)
    private String newPassword;

    @ApiModelProperty(value = "手机号")
    @Length(message = "手机号码不能超过{max}个字符", max = 25)
    private String mobileNumber;

    @ApiModelProperty(value = "机构id")
    @JsonSerialize(using = ToStringSerializer.class)
    @NotNull(message = "请选择机构")
    private Long orgId;

    @ApiModelProperty(value = "是否启用，0：停用，1：启用")
    private Boolean enable;

    @ApiModelProperty(value = "性别，MAN：男，WOMAN：女")
    private GenderEnum gender;

    @ApiModelProperty(value = "密码修改次数，默认为0")
    private Integer pwdCount;

    @ApiModelProperty(value = "密码修改时间")
    private Long pwdUpdateTime;

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

    @ApiModelProperty(value = "来源，SYSTEM：系统自带，ARCHIVES：档案")
    private UserSourceEnum source;

    @ApiModelProperty(value = "供应商id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long supplierId;

    @ApiModelProperty("软通智服用户同步状态")
    private RtzfSyncStatusEnum rtzfSyncStatus;

    @JsonSerialize(using = ToStringSerializer.class)
    @TableField(exist = false)
    @NotEmpty(message = "请选择角色")
    private Long[] roleIds;

    public String getNewPassword() {
        return newPassword;
    }

    public void setNewPassword(String newPassword) {
        this.newPassword = newPassword;
    }

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

    public void setRoleIds(Long[] roleIds) {
        this.roleIds = roleIds;
    }

    public GenderEnum getGender() {
        return gender;
    }

    public void setGender(GenderEnum gender) {
        this.gender = gender;
    }

    /**
     * 设置密码
     *
     * @param password
     */
    public void setPasswordInfo(String password) {
        this.password = Base64Util.encode(password.substring(password.length() - 6, password.length()).getBytes());
    }

    /**
     * 更新密码
     *
     * @param password
     */
    public void updatePasswordInfo(String password) {
        this.password = Base64Util.encode(password.substring(password.length() - 6, password.length()).getBytes());
    }

    public UserSourceEnum getSource() {
        return source;
    }

    public void setSource(UserSourceEnum source) {
        this.source = source;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getMobileNumber() {
        return mobileNumber;
    }

    public void setMobileNumber(String mobileNumber) {
        this.mobileNumber = mobileNumber;
    }

    public Long getOrgId() {
        return orgId;
    }

    public void setOrgId(Long orgId) {
        this.orgId = orgId;
    }

    public Boolean getEnable() {
        return enable;
    }

    public void setEnable(Boolean enable) {
        this.enable = enable;
    }

    public Integer getPwdCount() {
        return pwdCount;
    }

    public void setPwdCount(Integer pwdCount) {
        this.pwdCount = pwdCount;
    }

    public Long getPwdUpdateTime() {
        return pwdUpdateTime;
    }

    public void setPwdUpdateTime(Long pwdUpdateTime) {
        this.pwdUpdateTime = pwdUpdateTime;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public RtzfSyncStatusEnum getRtzfSyncStatus() {
        return rtzfSyncStatus;
    }

    public void setRtzfSyncStatus(RtzfSyncStatusEnum rtzfSyncStatus) {
        this.rtzfSyncStatus = rtzfSyncStatus;
    }

    public Long getSupplierId() {
        return supplierId;
    }

    public void setSupplierId(Long supplierId) {
        this.supplierId = supplierId;
    }
}
