package com.jiayue.ssi.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;

/**
 * 用户实体
 *
 * @author xsl
 * @version 3.0
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName(value = "sys_user")
public class SysUser extends BaseEntity implements UserDetails {
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 用户账号
     */
    private String username;
    /**
     * 用户密码
     */
    private String password;
    /**
     * 用户姓名
     */
    private String nickname;
    /**
     * 账号状态（0正常、1锁定（休眠）、2注销）
     */
    private String status;
    /**
     * 邮箱
     */
    private String mailbox;
    /**
     * 手机号码
     */
    private String phonenumber;
    /**
     * 失败次数
     */
    private Integer errNum;
    /**
     * 锁定时间
     */
    private Long lockTime;
    /** 最后修改密码时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date lastUpdatePwdTime;
    /** 最后登录IP */
    private String loginIp;

    /** 最后登录时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date loginDate;

    /**
     * 用户类型（0管理员、1业务用户）
     */
    private String usertype;

    /**
     * 账号有效期
     */
    @TableField(value = "exp_date",fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date expDate;

    @Override
    public boolean isEnabled() {
        return true;
    }
    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return password;
    }
}
