package com.ai.da.controller;

import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.common.response.Response;
import com.ai.da.model.dto.GetNotificationDTO;
import com.ai.da.model.vo.NotificationVO;
import com.ai.da.model.dto.PublishSysNotificationDTO;
import com.ai.da.service.MessageCenterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@Api(tags = "消息中心模块")
@Slf4j
@RestController
@RequestMapping("/api/message")
public class MessageCenterController {

    @Resource
    private MessageCenterService messageCenterService;

    // 获取未读消息总数
    @ApiOperation(value = "获取未读消息数")
    @GetMapping("/getUnreadCount")
    public Response<Map<String, Long>> getUnreadMessage(){
        return Response.success(messageCenterService.getAllTypeMessageUnreadCount());
    }

    // 获取历史消息
    @ApiOperation(value = "获取历史消息")
    @PostMapping("/getHistoryNotification")
    public Response<PageBaseResponse<NotificationVO>> getHistoryNotification(@Valid @RequestBody GetNotificationDTO getNotificationDTO) {
        return Response.success(messageCenterService.getHistoryNotification(getNotificationDTO));
    }

    // 已读消息
    @ApiOperation(value = "设置消息状态为已读")
    @PostMapping("/setReadStatus")
    public Response<Boolean> setReadStatus(@RequestParam("notificationIdList") List<Long> notificationIdList, @RequestParam("type") String type) {
        return Response.success(messageCenterService.setReadStatus(notificationIdList, type));
    }

    // 发布系统消息
    @ApiOperation(value = "发布系统消息")
    @PostMapping("/publishSysMessage")
    public Response<String> publishSysMessage(@Valid @RequestBody PublishSysNotificationDTO message) {
        messageCenterService.publishSystemNotification(message);
        return Response.success("success");
    }

    @ApiOperation(value = "一键已读")
    @PostMapping("/oneClickRead")
    public Response<String> setReadAll(@RequestParam("type") String type) {
        messageCenterService.setReadAll(type);
        return Response.success("success");
    }
}
