package com.ruoyi.common.core.domain.model;

import java.util.Collection;

import com.ruoyi.common.core.domain.entity.AppUser;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import com.alibaba.fastjson2.annotation.JSONField;

/**
 * 登录用户身份权限
 *
 * @author ruoyi
 */
@Data
public class AppLoginUser implements UserDetails
{

    private static final long serialVersionUID = 1L;
    private Long appUserId;

    private Long[] roles;
    private Long manageAccountId;
    private Long studentId;
    private String userName;
    private String token;
    private Long loginTime;
    private Long expireTime;
    /**
     * 用户信息
     */
    private AppUser appUser;

    public AppLoginUser(Long appUserId, Long[] roleId, Long studentId, String userName, Long manageAccountId, String token, Long loginTime, Long expireTime, AppUser appUser) {
        this.appUserId = appUserId;
        this.roles = roleId;
        this.studentId = studentId;
        this.userName = userName;
        this.manageAccountId = manageAccountId;
        this.token = token;
        this.loginTime = loginTime;
        this.expireTime = expireTime;
        this.appUser = appUser;
    }

    public AppLoginUser() {

    }

    public AppLoginUser(Long appUserId,String userName,Long manageAccountId,Long[] roles,Long studentId,AppUser appUser) {
        this.appUserId = appUserId;
        this.userName = userName;
        this.manageAccountId = manageAccountId;
        this.roles =roles;
        this.studentId = studentId;
        this.appUser = appUser;
    }

    public Long getAppUserId() {
        return appUserId;
    }

    public void setAppUserId(Long appUserId) {
        this.appUserId = appUserId;
    }

    @JSONField(serialize = false)
    @Override
    public String getPassword()
    {
        return appUser.getPassword();
    }

    @Override
    public String getUsername()
    {
        return appUser.getUserName();
    }

    /**
     * 账户是否未过期,过期无法验证
     */
    @JSONField(serialize = false)
    @Override
    public boolean isAccountNonExpired()
    {
        return true;
    }

    /**
     * 指定用户是否解锁,锁定的用户无法进行身份验证
     *
     * @return
     */
    @JSONField(serialize = false)
    @Override
    public boolean isAccountNonLocked()
    {
        return true;
    }

    /**
     * 指示是否已过期的用户的凭据(密码),过期的凭据防止认证
     *
     * @return
     */
    @JSONField(serialize = false)
    @Override
    public boolean isCredentialsNonExpired()
    {
        return true;
    }

    /**
     * 是否可用 ,禁用的用户不能身份验证
     *
     * @return
     */
    @JSONField(serialize = false)
    @Override
    public boolean isEnabled()
    {
        return true;
    }

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