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.dao.his.settings.SettingsDao;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.settings.notification.SendMessageParam;
import thyyxxk.webserver.service.PublicServer;
import thyyxxk.webserver.utils.ResultVoUtil;
import thyyxxk.webserver.websocket.WebSocketServer;

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

    @Autowired
    public Notification(SettingsDao dao, PublicServer publicServer) {
        this.dao = dao;
        this.publicServer = publicServer;
    }

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

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

}
