package com.zioinfo.kintex.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * STOMP over WebSocket — RenderJob 완료·승인 이벤트 실시간 푸시(design.md §1-4).
 * <ul>
 *   <li>핸드셰이크: {@code /ws}</li>
 *   <li>서버→클라 브로드캐스트 prefix: {@code /topic} (예: {@code /topic/render/{jobId}})</li>
 *   <li>클라→서버 prefix: {@code /app}</li>
 * </ul>
 * 나노바나나 Python 워커가 생성 완료를 백엔드에 알리면 백엔드가 해당 토픽으로 relay 한다.
 */
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableSimpleBroker("/topic");
        registry.setApplicationDestinationPrefixes("/app");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/ws").setAllowedOriginPatterns("*").withSockJS();
    }
}
