package kr.co.accura.wbx.spring.notification;

import kr.co.accura.wbx.spring.auth.WbxUserDetails;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.util.Map;

@RestController
@RequestMapping("${wbx.spring.api-prefix:/api}/notifications")
@RequiredArgsConstructor
public class NotificationController {

    private final SseNotificationService sseService;

    @GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitter stream(@AuthenticationPrincipal WbxUserDetails user) {
        return sseService.connect(user.getId());
    }

    @GetMapping("/unread-count")
    public Map<String, Object> unreadCount(@AuthenticationPrincipal WbxUserDetails user) {
        return Map.of("count", 0); // TODO: DB 연동 후 구현
    }
}
