package com.ho.business.controller;

import com.ho.business.service.MessageInfoService;
import com.ho.business.entity.MessageInfoVo;
import com.ho.business.vo.req.MessageInfoReqVo;
import com.ho.common.tools.annotation.TokenIgnore;
import com.ho.common.tools.constant.ContextConstant;
import com.ho.common.tools.exception.DataResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.List;
import java.util.Map;

@RestController
@RequestMapping(ContextConstant.BUSINESS + "messageInfo")
@Api(tags = "站内广播消息")
@Slf4j
public class MessageController {

    @Autowired
    MessageInfoService messageInfoService;


    @PostMapping("/modifyMessageInfo")
    @ApiOperation(value = "新增广播消息")
    public DataResult<MessageInfoVo> modifyMessageInfo(@RequestBody MessageInfoReqVo messageInfo){
        DataResult result =  new DataResult();
        MessageInfoVo newMessageInfo =   messageInfoService.modifyMessageInfo(messageInfo);
        result.setData(newMessageInfo);
        return result;
    }


    @PostMapping("/deleteMessage")
    @ApiOperation(value = "删除广播消息")
    public DataResult deleteMessage(@RequestBody List<String> messageIds){
        DataResult result =  new DataResult();
        messageInfoService.deleteMessage(messageIds);
        return result;
    }

    @PostMapping("/selectMessageInfo")
    @ApiOperation(value = "查询广播消息")
    public DataResult<MessageInfoReqVo> selectMessageInfo(@RequestBody Map<String,Object> condition){
        DataResult result =  new DataResult();
        List<MessageInfoReqVo> message = messageInfoService.selectMessageInfo(condition);
        result.setData(message);
        return result;
    }


    @PostMapping("/updateMessageReadStatus")
    @ApiOperation(value = "更新阅读状态")
    public DataResult updateMessageReadStatus(@RequestBody Map<String,Object> condition){
        DataResult result =  new DataResult();
        messageInfoService.updateMessageReadStatus(condition);
        return result;
    }

    @PostMapping("/jobUpdateMessageInfo")
    @TokenIgnore
    @ApiOperation(value = "定时任务刷新消息数据")
    public DataResult jobUpdateMessageInfo(){
        messageInfoService.jobUpdateMessageInfo();
        return DataResult.success();
    }









}
