package ervu_business_metrics.security.context;

import ervu_business_metrics.security.model.jwt.UserSession;
import ervu_business_metrics.security.model.jwt.authentication.JwtTokenAuthentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

@Component
public class SecurityContextImpl
    implements SecurityContext {
  @Override
  public String getRecruitmentId() {
    JwtTokenAuthentication jwtTokenAuthentication = (JwtTokenAuthentication)
        SecurityContextHolder.getContext().getAuthentication();
    if (jwtTokenAuthentication != null) {
      return jwtTokenAuthentication.getUserSession().recruitmentId();
    }
    else {
      return null;
    }
  }

  @Override
  public UserSession getUserSession() {
    JwtTokenAuthentication jwtTokenAuthentication = (JwtTokenAuthentication)
        SecurityContextHolder.getContext().getAuthentication();
    if (jwtTokenAuthentication != null) {
      return jwtTokenAuthentication.getUserSession();
    }
    else {
      return null;
    }
  }
}
