package ru.micord.ervu.account_applications.security.model.jwt.authentication;

import java.util.Collection;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import ru.micord.ervu.account_applications.security.model.UserSession;

public class JwtTokenAuthentication implements Authentication {

  private final UserSession userSession;
  private final String token;

  public JwtTokenAuthentication(UserSession userSession, String token) {
    this.userSession = userSession;
    this.token = token;
  }

  public UserSession getUserSession() {
    return userSession;
  }

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

  @Override
  public Object getCredentials() {
    return token;
  }

  @Override
  public Object getDetails() {
    return null;
  }

  @Override
  public Object getPrincipal() {
    return null;
  }

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

  @Override
  public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {

  }

  @Override
  public String getName() {
    return userSession.name();
  }
}
