package ee.tuleva.onboarding.auth.session;

import java.io.Serial;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;

@Component
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class GenericSessionStore implements Serializable {

  @Serial private static final long serialVersionUID = -648103071415508424L;

  private final Map<String, Object> sessionAttributes = new HashMap<>();

  public <T extends Serializable> void save(T sessionAttribute) {
    sessionAttributes.put(sessionAttribute.getClass().getName(), sessionAttribute);
  }

  public <T extends Serializable> Optional<T> get(Class clazz) {
    @SuppressWarnings("unchecked")
    T sessionAttribute = (T) sessionAttributes.get(clazz.getName());

    if (sessionAttribute == null) {
      return Optional.empty();
    }

    return Optional.of(sessionAttribute);
  }
}

@@ -195,32 +195,28 @@
 ork.
-context.annotation.Scope
+stereotype.Component
 ;%0Aim
@@ -240,16 +240,20 @@
 amework.
+web.
 context.
@@ -268,152 +268,46 @@
 on.S
-copedProxyMode;%0Aimport org.springframework.stereotype.Component;%0A%0A@Component%0A@Scope(value = %22session%22, proxyMode = ScopedProxyMode.TARGET_CLASS)
+essionScope;%0A%0A@Component%0A@SessionScope
 %0Apub

Revert "Revert "Use composed annotation for readability""