package ru.dragonestia.kubik.discovery.config;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
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;
import ru.dragonestia.kubik.discovery.component.UpdateStateNotifier;
import ru.dragonestia.kubik.discovery.ws.WebSocketHandler;
import tools.jackson.databind.ObjectMapper;

@EnableWebSocket
@RequiredArgsConstructor
@Configuration
public class WebSocketConfig implements WebSocketConfigurer {

    private final UpdateStateNotifier updateStateNotifier;
    private final ObjectMapper objectMapper;

    @Override
    public void registerWebSocketHandlers(@NonNull WebSocketHandlerRegistry registry) {
        registry.addHandler(new WebSocketHandler(updateStateNotifier, objectMapper), "/api/v1/server/updates/ws");
    }
}
