package eu.jonahbauer.wizard.server.socket;

import lombok.AccessLevel;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Getter(AccessLevel.PRIVATE)
    private final WizardSocketHandler wizardSocketHandler;

    public WebSocketConfig(WizardSocketHandler wizardSocketHandler) {
        this.wizardSocketHandler = wizardSocketHandler;
    }

    @Override
    public void registerWebSocketHandlers(@NotNull WebSocketHandlerRegistry registry) {
        registry.addHandler(getWizardSocketHandler(), "/").setAllowedOrigins("*");
    }
}
