package thyyxxk.webserver.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.service.PublicServer;
import thyyxxk.webserver.service.hutoolcache.CacheEnums;
import thyyxxk.webserver.service.hutoolcache.ExtraCache;
import thyyxxk.webserver.utils.ResultVoUtil;

import java.util.Map;

@Slf4j
@RestController
public class ShutDownController {

    private final PublicServer publicServer;
    private final ExtraCache extraCache;

    public ShutDownController(PublicServer publicServer, ExtraCache extraCache) {
        this.publicServer = publicServer;
        this.extraCache = extraCache;
    }

    @GetMapping("sendSystemUpdatesMessage")
    public ResultVo<String> sendSystemUpdatesMessage(String message) {
        extraCache.put(CacheEnums.SYSTEM_UPDATES_MESSAGE.getName(), message);
        publicServer.sendSystemAnnouncement();
        return ResultVoUtil.success();
    }

    @GetMapping("sendScrollingMessages")
    public ResultVo<String> sendScrollingMessages(String message) {
        extraCache.put(CacheEnums.SCROLLING_MESSAGES.getName(), message);
        publicServer.sendSystemAnnouncement();
        return ResultVoUtil.success();
    }

    @GetMapping("/getSystemAnnouncement")
    public ResultVo<Map<String, String>> getSystemAnnouncement() {
        return ResultVoUtil.success(extraCache.getMessage());
    }

}
