package com.ym.service.Impl;

import com.ym.service.MessageService;
import io.rong.methods.message._private.Private;
import io.rong.methods.message.chatroom.Chatroom;
import io.rong.methods.message.group.Group;
import io.rong.methods.message.history.History;
import io.rong.methods.message.system.MsgSystem;
import io.rong.methods.push.Push;
import io.rong.models.Result;
import io.rong.models.message.*;
import io.rong.models.push.BroadcastModel;
import io.rong.models.push.PushModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class MessageServiceImpl implements MessageService {

    @Value("${cn.rongcloud.im.appkey}")
    private String appKey;
    @Value("${cn.rongcloud.im.secret}")
    private String appSecret;

    private Private getPrivate(){
        return new Private(appKey,appSecret);
    }
    private Group getGroup(){
        return new Group(appKey,appSecret);
    }
    private Chatroom getChatroom(){
        return new Chatroom(appKey,appSecret);
    }
    private MsgSystem getMsgSystem(){
        return new MsgSystem(appKey,appSecret);
    }
    private History getHistory(){
        return new History(appKey,appSecret);
    }
    private Push getPush(){
        return new Push(appKey,appSecret);
    }

    @Override
    public Result privateSend(PrivateMessage privateMessage) throws Exception {
        return getPrivate().send(privateMessage);
    }

    @Override
    public Result privateRecall(RecallMessage recallMessage) throws Exception {
        return getPrivate().recall(recallMessage);
    }

    @Override
    public Result privateSendTemplate(TemplateMessage templateMessage) throws Exception {
        return getPrivate().sendTemplate(templateMessage);
    }

    @Override
    public Result groupSend(GroupMessage groupMessage) throws Exception {
        return getGroup().send(groupMessage);
    }

    @Override
    public Result groupSendDirection(GroupMessage groupMessage) throws Exception {
        return getGroup().sendDirection(groupMessage);
    }

    @Override
    public Result groupSendMention(MentionMessage mentionMessage) throws Exception {
        return getGroup().sendMention(mentionMessage);
    }

    @Override
    public Result groupRecall(RecallMessage recallMessage) throws Exception {
        return getGroup().recall(recallMessage);
    }

    @Override
    public Result chatroomSend(ChatroomMessage chatroomMessage) throws Exception {
        return getChatroom().send(chatroomMessage);
    }

    @Override
    public Result chatroomBroadcast(ChatroomMessage chatroomMessage) throws Exception {
        return getChatroom().broadcast(chatroomMessage);
    }

    @Override
    public Result systemSend(SystemMessage systemMessage) throws Exception {
        return getMsgSystem().send(systemMessage);
    }

    @Override
    public Result systemBroadcast(BroadcastMessage broadcastMessage) throws Exception {
        return getMsgSystem().broadcast(broadcastMessage);
    }

    @Override
    public Result systemSendTemplate(TemplateMessage templateMessage) throws Exception {
        return getMsgSystem().sendTemplate(templateMessage);
    }

    @Override
    public Result historyGet(String date) throws Exception {
        return getHistory().get(date);
    }

    @Override
    public Result historyRemove(String date) throws Exception {
        return getHistory().remove(date);
    }

    @Override
    public Result pushPush(PushModel pushModel) throws Exception {
        return getPush().push(pushModel);
    }

    @Override
    public Result pushMessage(BroadcastModel broadcastModel) throws Exception {
        return getPush().message(broadcastModel);
    }
}
