package cn.reghao.tnb.content.app.chat.service;

import cn.reghao.tnb.content.app.chat.model.dto.chat.ChatRecordGetRet;
import cn.reghao.tnb.message.api.model.EventType;
import cn.reghao.tnb.message.api.model.resp.EventMessageResp;
import cn.reghao.tnb.message.api.model.resp.EvtTalkResp;
import cn.reghao.tnb.message.api.model.resp.EvtTalkRevokeResp;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.springframework.stereotype.Service;

/**
 * @author reghao
 * @date 2023-11-28 16:46:56
 */
@Service
public class EventService {
    /*@DubboReference(check = false)
    private EventDispatcher eventDispatcher;*/
    private final Gson gson = new GsonBuilder().create();

    public void sendMessageEvent(int chatType, long userId, long receiverId, ChatRecordGetRet chatRecordGetRet) {
        EvtTalkResp<ChatRecordGetRet> resp = new EvtTalkResp<>(chatType, userId, receiverId, chatRecordGetRet);
        EventMessageResp<EvtTalkResp<ChatRecordGetRet>> eventMessage = new EventMessageResp<>(EventType.event_talk, resp);
        String jsonData = gson.toJson(eventMessage);

        /*eventDispatcher.sendMessage(receiverId, jsonData);
        eventDispatcher.sendMessage(userId, jsonData);*/
    }

    public void sendMessageEvent(long userId, long receiverId, EvtTalkRevokeResp evtTalkRevokeResp) {
        EventMessageResp<EvtTalkRevokeResp> eventMessage = new EventMessageResp<>(EventType.event_talk_revoke, evtTalkRevokeResp);
        String jsonData = gson.toJson(eventMessage);

        /*eventDispatcher.sendMessage(receiverId, jsonData);
        eventDispatcher.sendMessage(userId, jsonData);*/
    }

    public void sendApplyEvent(long receiverId) {
        String resp = "";
        EventMessageResp<String> eventMessage = new EventMessageResp<>(EventType.event_contact_apply, resp);
        String jsonData = gson.toJson(eventMessage);
        //eventDispatcher.sendMessage(receiverId, jsonData);
    }
}
