package com.gree.mall.manager.controller.notice;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.notice.NoticeLogic;
import com.gree.mall.manager.plus.entity.Notice;
import com.gree.mall.manager.plus.entity.SecKillActivity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@Api(value = "消息通知接口", tags = {"消息通知接口"})
@RequestMapping(value = "/notice/", produces = "application/json; charset=utf-8")
public class NoticeController {

    @Autowired
    private NoticeLogic noticeLogic;

    @GetMapping("/list")
    @ApiOperation(value = "获取消息列表")
    public ResponseHelper<IPage<Notice>> list(HttpServletRequest request,
                                              @ApiParam(value = "已读标记true:已读,false:未读,不传获取全部消息", required = false) @RequestParam(required = false) Boolean readFlag,
                                              @ApiParam(value = "页号", required = true) @RequestParam Integer pageNum,
                                              @ApiParam(value = "页大小", required = true) @RequestParam Integer pageSize
    ) throws Exception {
        return ResponseHelper.success(noticeLogic.page(request,readFlag, pageNum, pageSize));
    }


    @GetMapping("/list/count")
    @ApiOperation(value = "未读消息数量")
    public ResponseHelper<Integer> unreadCount(HttpServletRequest request) throws Exception {
        return ResponseHelper.success(noticeLogic.unreadCount(request));
    }


    @PostMapping("/mark/read")
    @ApiOperation(value = "标记已读")
    public ResponseHelper markRead(HttpServletRequest request,@ApiParam(value = "通知消息id数组", required = true) @RequestBody String[] noticeIds) throws Exception {
        noticeLogic.markRead(noticeIds);
        return ResponseHelper.success();
    }


    @PostMapping("/mark/read/all")
    @ApiOperation(value = "全部标记已读")
    public ResponseHelper markReadAll(HttpServletRequest request) throws Exception {
        noticeLogic.markReadAll(request);
        return ResponseHelper.success();
    }


}
