package com.mmc.iuav.user.controller;

import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.model.vo.SystemMessageVO;
import com.mmc.iuav.user.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(tags = "消息管理")
@RequestMapping("/message/")
@RestController
public class MessageController  extends BaseController{
    @Resource
    private MessageService messageService;

    @ApiOperation(value = "后台发布消息——新增系统消息")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
    @PostMapping("/insertSystemMessage")
    public ResultBody insertSystemMessage(@RequestBody SystemMessageVO messageVO){
        return messageService.insertSystemMessage(messageVO);
    }

    @ApiOperation(value = "后台——根据ID查询系统消息")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
    @GetMapping("/selectSystemMessageById")
    public ResultBody selectSystemMessageById(@RequestParam Integer id){
        return messageService.selectSystemMessageById(id);
    }
    @ApiOperation(value = "后台——系统消息列表")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
    @GetMapping("/selectAllSystemMessage")
    public ResultBody selectAllSystemMessage(){
        return messageService.selectAllSystemMessage();
    }

    @ApiOperation(value = "后台——删除消息")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
    @PostMapping("/removeMessage")
    public ResultBody removeMessage(@RequestParam Integer id){
        return messageService.removeMessage(id);
    }

    @ApiOperation(value = "用户——系统消息列表")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
    @GetMapping("/systemMessageListByUser")
    public ResultBody selectAllSystemMessageByUser(HttpServletRequest request){
        Integer userId = this.getUserLoginInfoFromRedis(request).getUserAccountId();
        return messageService.selectAllSystemMessageByReceive(userId);
    }
    @ApiOperation(value = "用户查看——系统消息详情")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
    @GetMapping("/showSystemMessageByUser")
    public ResultBody showSystemMessageByUser(HttpServletRequest request, @RequestParam Integer messageId){
        Integer userId = this.getUserLoginInfoFromRedis(request).getUserAccountId();
        return messageService.showSystemMessageByUser(userId,messageId);
    }

    @ApiOperation(value = "用户——删除接收的消息")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
    @PostMapping("/removeMessageByUser")
    public ResultBody removeMessageByUser(@RequestParam Integer id){
        return messageService.removeMessageByUser(id);
    }
}
