package com.example.sse.api;

import com.example.sse.core.SseChannelBus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

@RestController
@RequestMapping("/sse")
public class SseController {

    private final SseChannelBus bus;

    public SseController(SseChannelBus bus) { // ✅ 같은 빈 주입
        this.bus = bus;
    }

    @GetMapping(value = "/subscribe", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitter subscribe(@RequestParam String channelId) {
        System.out.println("GET /subscribe?channelId=" + channelId);

        return bus.subscribe(channelId, 30 * 60 * 1000L);
    }
}
