package com.copy.trade.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bizzan.bitrade.entity.transform.AuthMember;
import com.copy.trade.constant.DogeApi;
import com.copy.trade.entity.base.BaseQueryForm;
import com.copy.trade.entity.form.MessageQueryForm;
import com.copy.trade.entity.po.Customer;
import com.copy.trade.entity.po.Message;
import com.copy.trade.entity.vo.MessageVo;
import com.copy.trade.entity.vo.NoticeVo;
import com.copy.trade.service.IMessageService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value = "推送消息接口", tags = "推送消息接口")
@RestController
@RequestMapping("/message")
public class MessageController {
	IMessageService service;
	
	@Autowired
	public MessageController(IMessageService service) {
		this.service = service;
	}
	
	@ApiOperation(value = "获取是否有未读消息")
	@GetMapping("/unread")
	public boolean unread(@SessionAttribute(DogeApi.SESSION_MEMBER) AuthMember authMember){
		return service.listUnreadByCustomerId(authMember.getId()).size()>0;
		
	}

	@ApiOperation(value = "获取消息列表")
	@PostMapping("/list")
	public Page<MessageVo> list(@SessionAttribute(DogeApi.SESSION_MEMBER) AuthMember authMember, @RequestBody BaseQueryForm baseQueryForm){
		return service.listByCustomerId(authMember.getId(), baseQueryForm.newFormPage());
	}
	
	
	@ApiOperation(value = "公告列表,最近5条")
	@PostMapping("/notice-list")
	public List<NoticeVo> noticeList(){
		return service.noticeList();
	}
	
	
}
