package com.mmc.iuav.user.controller;

import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.model.qo.MessageQO;
import com.mmc.iuav.user.model.vo.SystemMessageVO;
import com.mmc.iuav.user.service.MessageService;
import io.swagger.annotations.*;
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(@ApiParam(value = "消息ID") @RequestParam Integer id){
        return messageService.selectSystemMessageById(id);
    }
    @ApiOperation(value = "后台——系统消息列表")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
    @PostMapping("/selectAllSystemMessage")
    public ResultBody selectAllSystemMessage(@RequestBody MessageQO messageQO){
        return ResultBody.success(messageService.selectAllSystemMessage(messageQO));
    }

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

    @ApiOperation(value = "用户——系统消息列表")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
    @PostMapping("/systemMessageListByUser")
    public ResultBody selectAllSystemMessageByUser(HttpServletRequest request,@RequestBody MessageQO messageQO){
        Integer userId = this.getUserLoginInfoFromRedis(request).getUserAccountId();
        return ResultBody.success(messageService.selectAllSystemMessageByReceive(userId,messageQO));
    }
    @ApiOperation(value = "用户查看——系统消息详情")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
    @GetMapping("/showSystemMessageByUser")
    public ResultBody showSystemMessageByUser(HttpServletRequest request,@ApiParam(value = "消息ID") @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(HttpServletRequest request,@ApiParam(value = "消息ID") @RequestParam Integer messageId){
        Integer userId = this.getUserLoginInfoFromRedis(request).getUserAccountId();
        return messageService.removeMessageByUser(userId,messageId);
    }
}
