package com.tsi.monitoring.webSocket;

import com.tsi.monitoring.repository.GlobalStatusInfoRepository;
import com.tsi.monitoring.service.SectionService;
import com.tsi.monitoring.service.UtisService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
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
@RequiredArgsConstructor
public class WebSocketConfig implements WebSocketConfigurer {
    private final GlobalStatusInfoRepository repository;
    private final UtisService utisService;
    private final SectionService sectionService;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new MonitoringWebSocketHandler(repository, utisService, sectionService), "/ws.do")
                .setAllowedOriginPatterns("*")
                .withSockJS()
                .setClientLibraryUrl("http://localhost:8999/static/js/sockjs.min.js");;
    }
}
