package com.qmth.themis.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.themis.business.base.BaseEntity;
import com.qmth.themis.business.constant.SystemConstant;
import com.qmth.themis.business.util.UidUtil;
import com.qmth.themis.common.util.Base64Util;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.UnsupportedEncodingException;
import java.util.Objects;

/**
 * @Description: 用户
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2020/6/25
 */
@ApiModel(value = "t_b_user", description = "用户")
public class TBUser extends BaseEntity {

    @ApiModelProperty(value = "用户名")
    @TableField(value = "login_name")
    private String loginName;

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

    @ApiModelProperty(value = "手机号")
    @TableField(value = "mobile_number")
    private String mobileNumber;

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

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "机构id")
    @TableField(value = "org_id")
    private Long orgId;

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

    @ApiModelProperty(value = "姓名")
    @TableField(value = "name")
    private String name;

    @ApiModelProperty(value = "强制修改密码，false：未修改，true：已修改")
    private Boolean pwdForce;

    public TBUser() {

    }

    public TBUser(Long orgId, String loginName, String name, Long createId) {
        setId(UidUtil.nextId());
        this.orgId = orgId;
        this.loginName = loginName;
        this.name = name;
        setCreateId(createId);
        this.password = SystemConstant.DEFAULT_PASSWORD;
    }

    public TBUser(Long orgId, String loginName, String name, Long createId, String password) throws UnsupportedEncodingException {
        setId(UidUtil.nextId());
        this.orgId = orgId;
        this.loginName = loginName;
        this.name = name;
        setCreateId(createId);
        if (Objects.nonNull(password) && !Objects.equals(password.trim(), "")) {
            this.password = Base64Util.encode(password.trim().getBytes(SystemConstant.CHARSET_NAME));
        } else {
            this.password = SystemConstant.DEFAULT_PASSWORD;
        }
    }

    public Boolean getPwdForce() {
        return pwdForce;
    }

    public void setPwdForce(Boolean pwdForce) {
        this.pwdForce = pwdForce;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLoginName() {
        return loginName;
    }

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

    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 Integer getEnable() {
        return enable;
    }

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

    public Long getOrgId() {
        return orgId;
    }

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

    public String getRemark() {
        return remark;
    }

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

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        TBUser tbUser = (TBUser) o;
        return Objects.equals(loginName, tbUser.loginName) &&
                Objects.equals(password, tbUser.password) &&
                Objects.equals(enable, tbUser.enable) &&
                Objects.equals(orgId, tbUser.orgId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(loginName, password, enable, orgId);
    }
}
