package org.ta.pddserver.config.security;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Data
public class RoleUserDetails implements UserDetails {
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

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

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return UserDetails.super.isAccountNonExpired();
    }

    private String uid;
    private String username;
    private String password;
    private List<String> role;
    private List<String> authorities;
    private String loginIp;
    private Long expireTime;

    public void addRole(String role){
        if (this.role == null){
            this.role = new ArrayList<String>();
        }
        this.role.add(role);
    }

    public void addAuthority(String authority){
        if (this.authorities == null){
            this.authorities = new ArrayList<>();
        }
        this.authorities.add(authority);
    }

}
