package eu.jonahbauer.wizard.server.debug;

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

@Configuration
@Profile("debug")
public class DebugWebSocketConfig implements WebSocketConfigurer {

    @Getter(AccessLevel.PRIVATE)
    private final DebugSocketHandler debugSocketHandler;

    public DebugWebSocketConfig(DebugSocketHandler debugSocketHandler) {
        this.debugSocketHandler = debugSocketHandler;
    }

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