package com.iamberry.sys;

import org.hibernate.validator.constraints.*;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Date;

/**
 * 管理员信息
 * @author 献
 * @company 深圳爱贝源科技有限公司
 * @website www.iamberry.com
 * @tel 18271840547
 * @date 2017/5/12
 */
public class Admin implements Serializable {

    private static final long serialVersionUID = -5830255406911681115L;

    private Integer adminId;

    private Integer ruleId;

    private Integer supplierId;

    /**
     * 管理员姓名
     */
    @NotBlank(message="姓名不能为空")
    @Length(min=2,max=10,message="姓名必须由2~10个字组成")
    private String adminName;

    /**
     * 性别
     */
    @Range(min=1,max=2,message="性别输入有误")
    private Integer adminSex;

    /**
     * 电话
     */
    @Pattern(regexp = "\\d{4}-\\d{8}|\\d{4}-\\d{7}|\\d(3)-\\d(8)", message = "电话号码输入有误!")
    private String adminTel;

    /**
     * 登录账户
     */
    private String adminAccount;

    /**
     * 密码
     */
    @Pattern(regexp="(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}",message="密码必须是6~16位数字和字母的组合")
    private String adminPassword;

    /**
     * 盐值
     */
    private String adminSalt;

    /**
     * 1：正常使用 2：已停止使用
     */
    private Integer adminStatus;

    /**
     * 邮箱
     */
    @Email(message = "邮箱输入有误!")
    private String adminMail;

    /**
     * 创建时间
     */
    private Date adminCreateTime;

    /**
     * 修改时间
     */
    private Date adminUpdateTime;

    private SysRule rule;

    public SysRule getRule() {
        return rule;
    }

    public void setRule(SysRule rule) {
        this.rule = rule;
    }

    public Integer getSupplierId() {
        return supplierId;
    }

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

    public Integer getAdminId() {
        return adminId;
    }

    public String getAdminName() {
        return adminName;
    }

    public Integer getAdminSex() {
        return adminSex;
    }

    public String getAdminTel() {
        return adminTel;
    }

    public String getAdminAccount() {
        return adminAccount;
    }

    public String getAdminPassword() {
        return adminPassword;
    }

    public String getAdminSalt() {
        return adminSalt;
    }

    public String getAdminMail() {
        return adminMail;
    }

    public Date getAdminCreateTime() {
        return adminCreateTime;
    }

    public void setAdminId(Integer adminId) {
        this.adminId = adminId;
    }


    public void setAdminName(String adminName) {
        this.adminName = adminName;
    }

    public void setAdminSex(Integer adminSex) {
        this.adminSex = adminSex;
    }

    public void setAdminTel(String adminTel) {
        this.adminTel = adminTel;
    }

    public void setAdminAccount(String adminAccount) {
        this.adminAccount = adminAccount;
    }

    public void setAdminPassword(String adminPassword) {
        this.adminPassword = adminPassword;
    }

    public void setAdminSalt(String adminSalt) {
        this.adminSalt = adminSalt;
    }

    public void setAdminMail(String adminMail) {
        this.adminMail = adminMail;
    }

    public void setAdminCreateTime(Date adminCreateTime) {
        this.adminCreateTime = adminCreateTime;
    }

    public void setAdminStatus(Integer adminStatus) {
        this.adminStatus = adminStatus;
    }

    public Integer getAdminStatus() {
        return adminStatus;
    }

    public Date getAdminUpdateTime() {
        return adminUpdateTime;
    }

    public void setAdminUpdateTime(Date adminUpdateTime) {
        this.adminUpdateTime = adminUpdateTime;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public Integer getRuleId() {
        return ruleId;
    }

    public void setRuleId(Integer ruleId) {
        this.ruleId = ruleId;
    }

    /**
     * 本函数输出将作为默认的<shiro:principal/>输出.
     */
    @Override
    public String toString() {
        return adminAccount;
    }

    /**
     * 重载hashCode,只计算adminAccount;
     */
    @Override
    public int hashCode() {
        return adminAccount.hashCode();
    }

    /**
     * 重载equals,只计算loginName;
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Admin other = (Admin) obj;
        if (adminAccount == null) {
            return false;
        } else if (!adminAccount.equals(other.getAdminAccount())) {
            return false;
        }
        return true;
    }
}
