package com.ruoyi.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.annotations.UserLoginToken;
import com.ruoyi.common.page.PageResult;
import com.ruoyi.controller.req.AppMessageReadOrDeleteReq;
import com.ruoyi.controller.req.MessageReadOrDeleteReq;
import com.ruoyi.frequency.appmessage.entity.AppMessage;
import com.ruoyi.frequency.appmessage.service.AppMessageService;
import com.ruoyi.response.ResponseData;
import com.ruoyi.vo.BodyIdReq;
import com.ruoyi.vo.PageBasic;
import com.ruoyi.vo.RyController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 消息中心
 * @author liwenlong
 *
 */
@CrossOrigin
@RestController
@RequestMapping("/api/message")
@Api(tags = "消息中心")
public class ApiAppMessageController extends RyController {


    @Autowired
    private AppMessageService appMessageService;

    @UserLoginToken
    @PostMapping("/messagePage")
    @ApiOperation(value = "系统消息列表" , notes = "系统消息列表")
    public ResponseData<PageResult<Page<AppMessage>>> messagePage(@RequestBody @Valid PageBasic req) {
        return this.appMessageService.messagePage(getUserVo(),req);
    }

    @UserLoginToken
    @PostMapping("/messageDetail")
    @ApiOperation(value = "系统消息详情" , notes = "系统消息详情")
    public ResponseData<AppMessage> messageDetail(@RequestBody @Valid BodyIdReq req) {
        return this.appMessageService.messageDetail(req.getId(),getUserVo());
    }

    @UserLoginToken
    @PostMapping("/appMessageReadOrDelete")
    @ApiOperation(value = "系统消息列表_已读，删除消息" , notes = "系统消息列表_已读，删除消息")
    public ResponseData appMessageReadOrDelete(@RequestBody @Valid MessageReadOrDeleteReq req) {
        return appMessageService.appMessageReadOrDelete(req, getUserVo());
    }

}
