package com.dayou.controller;

import com.dayou.annotation.IgnoreAuth;
import com.dayou.message.MessageServerCenter;
import com.dayou.message.handler.SystemMessageHandler;
import com.dayou.service.IMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.entity.Message;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * 消息
 *
 * @author wucl
 * @since 2023-06-30
 */
@RestController
@RequestMapping("message")
@Slf4j
public class MessageController {

    @Autowired
    private SystemMessageHandler systemMessageHandler;

    @Autowired
    private IMessageService messageService;

    @GetMapping("/notRead")
    public RestResponse<List<Message>> messageRedPoint(){
        List<Message> list = systemMessageHandler.messageRedPoint();
        return RestResponse.data(list);
    }

    /**
     * 更新消息已读状态
     * @param id
     * @return
     */
    @GetMapping("/updateRead/{id}")
    public RestResponse<Boolean> updateRead(@PathVariable("id") Long id){
        Boolean result = systemMessageHandler.readMessage(id);
        return RestResponse.data(result);
    }

    /**
     * 一键已读
     * @return
     */
    @GetMapping("/allRead")
    public RestResponse<Boolean> allRead(){
        Boolean result = messageService.allRead();
        return RestResponse.data(result);
    }

    @IgnoreAuth
    @GetMapping("/websocket")
    public void sendWebSocket(){
        messageService.sendWebSocket();
    }
}

