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

import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.gree.mall.miniapp.annotation.ApiNotAuth;
import com.gree.mall.miniapp.bean.notice.NoticeRecordVO;
import com.gree.mall.miniapp.exception.RemoteServiceException;
import com.gree.mall.miniapp.helper.ResponseHelper;
import com.gree.mall.miniapp.logic.notice.NoticeLogic;
import com.gree.mall.miniapp.plus.entity.Notice;
import com.gree.mall.miniapp.plus.entity.NoticeRecord;
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;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

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

    @Autowired
    private NoticeLogic noticeLogic;



@ApiNotAuth
    @PostMapping("/listNotice")
    @ApiOperation(value = "系统公告-列表")
    public ResponseHelper<IPage<NoticeRecordVO>> listNotice(
            @ApiParam(value = "公告类型 A 通知 B 公关",required = true) @RequestParam(required = true) String type,
            @ApiParam(value = "pageNo",required = true) @RequestParam Integer pageNo,
            @ApiParam(value = "pageSize",required = true) @RequestParam Integer pageSize
            ) throws RemoteServiceException {
        IPage<NoticeRecordVO> stockBeanIPage = noticeLogic.listNotice(type,pageNo,pageSize);
        return ResponseHelper.success(stockBeanIPage);
    }


    @GetMapping("/detailNotice")
    @ApiOperation(value = "系统公告详情")
    public ResponseHelper<NoticeRecordVO> detailNotice(
            @ApiParam(value = "id", required = true) @RequestParam(required = true) String id
    ){
        NoticeRecordVO detail = noticeLogic.detailNotice(id);
        return ResponseHelper.success(detail);
    }


    @GetMapping("/list/count")
    @ApiOperation(value = "未读消息数量")
    public ResponseHelper<Integer> unreadCount(  @ApiParam(value = "SYSTEM 系统公告  NOTICE 活动", required = false) @RequestParam (required = false)String noticeType,
                                                 @ApiParam(value = "YES 已读  NO 未读", required = true) @RequestParam String readFlag,
                                                 HttpServletRequest request) {
        return ResponseHelper.success(noticeLogic.unreadCount(request,noticeType,readFlag));
    }


    @PostMapping("/mark/read")
    @ApiOperation(value = "标记消息已读")
    public ResponseHelper markRead(
            @ApiParam(value = "通知消息id数组", required = true) @RequestParam List<String> ids
    ) throws Exception {
        noticeLogic.markRead(ids);
        return ResponseHelper.success();
    }


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


}
