package tutorial.core.security;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import tutorial.core.models.entities.Account;

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

/**
 * 
 * @author Xavier
 */
public class AccountUserDetails implements UserDetails {
    private final Account account;

    public AccountUserDetails(Account account) {
        this.account = account;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        GrantedAuthority authority = new GrantedAuthority() {
            @Override
            public String getAuthority() {
                return "USER";
            }
        };

        ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
        authorities.add(authority);
        return authorities;
        /*TODO add admin/user/student permissions */
    }

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

    @Override
    public String getUsername() {
        return account.getName();
    }

    public Account getAccount() {
        return account;
    }
    
    @Override
    public boolean isAccountNonExpired() {
        /*TODO*/
        return true;
    }

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

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

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