package com.unicorn.hgzero.meeting.infra.config;

import com.unicorn.hgzero.meeting.infra.websocket.WebSocketHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;

/**
 * WebSocket 설정
 * 실시간 회의록 협업을 위한 WebSocket 설정
 */
@Configuration
@EnableWebSocket
@RequiredArgsConstructor
@Slf4j
public class WebSocketConfig implements WebSocketConfigurer {

    private final WebSocketHandler webSocketHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 회의록 실시간 협업 WebSocket 엔드포인트
        registry.addHandler(webSocketHandler, "/ws/minutes/{minutesId}")
                .setAllowedOriginPatterns("*") // CORS 설정
                .withSockJS(); // SockJS 지원

        log.info("WebSocket 핸들러 등록 완료 - endpoint: /ws/minutes/{minutesId}");
    }
}