package cn.axzo.msg.center.webapi;

import cn.axzo.core.domain.PageResult;
import cn.axzo.framework.auth.annotation.PreBuildContext;
import cn.axzo.msg.center.api.request.CmsMsgQueryReq;
import cn.axzo.msg.center.api.request.GeneralMessageReq;
import cn.axzo.msg.center.api.request.MsgReturnParamRes;
import cn.axzo.msg.center.api.response.MessageNewRes;
import cn.axzo.msg.center.api.response.MessageTotalRes;
import cn.axzo.msg.center.domain.enums.UserTypeEnum;
import cn.axzo.msg.center.inside.notices.service.MessageCoreService;
import cn.axzo.msg.center.inside.notices.service.MessageRecordService;
import cn.azxo.framework.common.model.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author zhangPeng
 * @description
 * @date 2021/2/4 15:44
 */
@Slf4j
@RestController
@RequestMapping("webApi/message")
public class MessageController {



  @Autowired
  private MessageCoreService messageCoreService;
  @Resource
  private MessageRecordService messageRecordService;


  /**
   * 新增推送消息接口，发送push消息，站内信
   *
   * @param message
   * @return 消息唯一主键
   */
  @RequestMapping(value = "api/message/push", method = RequestMethod.POST)
  CommonResponse<List<MsgReturnParamRes>> pushMsg(@RequestBody GeneralMessageReq message){
    return CommonResponse.success(messageRecordService.pushMsg(message));
  }

  /**
   * 消息\待办数量总数
   *
   * @return
   */
  @GetMapping("inner/msg/total")
  //@PreBuildContext
  public CommonResponse<MessageTotalRes> msgTotal(Long personId, Long identityId, UserTypeEnum userTypeEnum) {
    log.info("msgTotal executing...");
    return CommonResponse.success(messageCoreService.statisticsMsg(personId,identityId,userTypeEnum));
  }

  /**
   * 消息列表搜索、待办列表
   *
   * @param req
   * @return
   */
  @PostMapping("inner/msg/list")
  @PreBuildContext
  public CommonResponse<PageResult<MessageNewRes>> msgList(@RequestBody @Valid CmsMsgQueryReq req) {
    log.info("msgList executing...");
    return CommonResponse.success(messageCoreService.listMsgInfo(req));
  }
}
