package com.muyu.server.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.domain.message.Message;
import com.muyu.domain.message.MessageReq;
import com.muyu.domain.message.MessageSendReq;
import com.muyu.server.service.MessageService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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;

/**
 * 站内信控制层
 * @Author：weiran
 * @Package：com.muyu.cloud.faultmanage.controller
 * @Project：cloud-server-8
 * @name：MessageController
 * @Date：2024/9/22 10:56
 */
@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 消息发送
     * @param messageSendReq
     * @return
     */
    @PostMapping("/sendmessage")
    @Operation(summary = "发送消息",description = "站内信消息发送")
    public Result sendmessage(@Validated MessageSendReq messageSendReq){
        messageService.sendmessage(messageSendReq);
        return Result.success(null,"发送成功");
    }

    /**
     * 消息查看
     * @param messageReq
     * @param
     * @return
     */
    @PostMapping("/messagelist")
    @Operation(summary = "消息查看(能根据登录人新的信息查看当前登录人的消息栏)",description = "消息查看")
    public Result selectmessage(@Validated @RequestBody MessageReq messageReq){
        return Result.success(messageService.selectmessage(messageReq));
    }

    /**
     * 查看消息改变状态
     * @param message
     * @return
     */
    @PostMapping("/changestatus")
    @Operation(summary = "状态改变",description = "状态改变")
    public Result changestatus(@RequestBody Message message){
        messageService.changestatus(message);
        return Result.success(null,"成功");
    }


    /**
     * 查看未读的消息
     * @return
     */
    @PostMapping("/unread")
    @Operation(summary = "查看未读的消息",description = "查看未读的消息")
    public Result unread(){
        return Result.success(messageService.unread());
    }




}
