package com.m2pool.chat.controller;

import com.m2pool.chat.entity.StompPrincipal;
import com.m2pool.chat.service.StompService;
import com.m2pool.chat.vo.UserMessageVo;
import com.m2pool.common.core.web.Result.AjaxResult;
import com.m2pool.common.core.web.controller.BaseController;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.simp.annotation.SendToUser;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * @Description TODO
 * @Date 2025/2/24 15:05
 * @Author 杜懿
 */
@Controller
public class StompController extends BaseController {




    @Resource
    private StompService stompService;

    /**
     * 发送消息给普通用户和游客
     * @param userMessageVo 消息体
     * @return 返回值通过CommonMessageConvert消息转换器转换
     */
    @MessageMapping("/send/message/to/user")
    @SendToUser("/queue/user")
    public AjaxResult sendMessageToUser(StompPrincipal principal, @Payload UserMessageVo userMessageVo) {
        return stompService.sendMessageToUser(principal,userMessageVo);
    }


    /**
     * 发送消息到对应的客服
     * @param userMessageVo 消息体
     * @return 返回值通过CommonMessageConvert消息转换器转换
     */
    @MessageMapping("/send/message/to/customer")
    @SendToUser("/queue/customer/")
    public AjaxResult sendMessageToCustomer(StompPrincipal principal, @Payload UserMessageVo userMessageVo) {
        return stompService.sendMessageToCustomer(principal,userMessageVo);
    }
}
