package com.muchinfo.mtp3pojos.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 系统管理员表
 * </p>
 *
 * @author XKF
 * @since 2024-03-21
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("SYSTEMMANAGER")
@ApiModel(value="Systemmanager对象", description="系统管理员表")
@AllArgsConstructor
@NoArgsConstructor
@Builder
@KeySequence(value = "SEQ_SYSTEMMANAGER")
public class Systemmanager extends Model<Systemmanager> implements UserDetails,Serializable{

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "自增ID")
    @TableId(value = "AUTOID",type = IdType.INPUT)
    private Long autoid;

    @ApiModelProperty(value = "用户类型 - 1- 交易所管理员   2- 机构管理员 3-子机构管理员")
    @TableField("RELETYPE")
    private Integer reletype;

    @ApiModelProperty(value = "用户登录账号,唯一索引")
    @TableField("LOGINCODE")
    private String logincode;

    @ApiModelProperty(value = "用户姓名")
    @TableField("USERNAME")
    private String username;

    @ApiModelProperty(value = "加密方式采用 用户名+密码  ,采用 SHA 算法")
    @TableField("PASSWORD")
    private String password;

    @ApiModelProperty(value = "所属机构ID")
    @TableField("AREAUSERID")
    private Long areauserid;

    @ApiModelProperty(value = "密码失效日期")
    @TableField("PWDEXPDATE")
    private Date pwdexpdate;

    @ApiModelProperty(value = "用户状态： 1启用  2停用  3锁定(密码错误时锁定)")
    @TableField("MANAGERSTATUS")
    private Integer managerstatus;

    @ApiModelProperty(value = "登录状态:1未登录 2已登录")
    @TableField("LOGINSTATUS")
    private Integer loginstatus;

    @ApiModelProperty(value = "是否默认管理员 - 0:不是默认 1:默认管理员")
    @TableField("ISDEFAULT")
    private Integer isdefault;

    @ApiModelProperty(value = "登录时间")
    @TableField("LOGINTIME")
    private Date logintime;

    @ApiModelProperty(value = "登录IP")
    @TableField("LOGINIP")
    @Builder.Default
    private String loginip = "";

    @ApiModelProperty(value = "登录端口")
    @TableField("LOGINPORT")
    private Long loginport;

    @ApiModelProperty(value = "登录失败次数")
    @TableField("LOGINFAILNUM")
    private Integer loginfailnum;

    @ApiModelProperty(value = "修改人ID")
    @TableField("UPLOGINID")
    private Long uploginid;

    @ApiModelProperty(value = "修改时间")
    @TableField("MODIFYTIME")
    private Date modifytime;

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

    @ApiModelProperty(value = "是否启用MAC地址 - 0:否 1:是")
    @TableField("ONYMAC")
    private Integer onymac;

    @ApiModelProperty(value = "账号类型 - 1:管理员 2:交易员")
    @TableField("MANAGERTYPE")
    private Integer managertype;

    @ApiModelProperty(value = "系统类型 - 1:旧管理端 2:新管理端")
    @TableField("SYSTEMTYPE")
    private Integer systemtype;

    @TableField(exist = false)
    private List<GrantedAuthority> authorities;

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

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

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

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

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