package thyyxxk.webserver.controller.settings;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.settings.notification.SendMessageParam;
import thyyxxk.webserver.service.PublicServer;
import thyyxxk.webserver.service.externalhttp.WebSocketService;

@Slf4j
@RestController
@RequestMapping("/notification")
public class Notification {
    private final PublicServer publicServer;
    private final WebSocketService socketService;

    @Autowired
    public Notification(PublicServer publicServer, WebSocketService socketService) {
        this.publicServer = publicServer;
        this.socketService = socketService;
    }

    @GetMapping("/getOnlineCount")
    public ResultVo<Integer> getOnlineCount() {
        return socketService.getOnlineCount();
    }

    @PostMapping("/sendMessageToAll")
    public ResultVo<String> sendMessage(@RequestBody @Validated SendMessageParam param) {
        return publicServer.sendMessage(param);
    }

}
