package thyyxxk.webserver.controller.socketmessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.socketmessage.MessageIndex;
import thyyxxk.webserver.entity.socketmessage.SocketMessage;
import thyyxxk.webserver.entity.socketmessage.SystemMessage;
import thyyxxk.webserver.service.socketmessage.SocketMessageService;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/socketMessage")
public class SocketMessageController {
    private final SocketMessageService service;

    @Autowired
    public SocketMessageController(SocketMessageService service) {
        this.service = service;
    }

    @GetMapping("/selectSystemMessages")
    public ResultVo<List<SystemMessage>> selectSystemMessages(@RequestParam("date") String date) {
        return service.selectSystemMessages(date);
    }

    @PassToken
    @PostMapping("/onPageRefresh")
    public ResultVo<Map<String, Object>> onPageRefresh(@RequestBody List<String> exclude) {
        return service.onPageRefresh(exclude);
    }

    @GetMapping("/fetchAllSenders")
    public ResultVo<List<MessageIndex>> fetchAllSenders() {
        return service.fetchAllSenders();
    }

    @PostMapping("/fetchAllMessages")
    public ResultVo<List<SocketMessage>> fetchAllMessages(@RequestBody SocketMessageService.FetchMessage sender) {
        return service.fetchAllMessages(sender);
    }
}
