package com.bc_chat.im.redpackage;

import com.jrmf360.rylib.common.util.q;
import com.jrmf360.rylib.rp.extend.CurrentUser;

import java.util.ArrayList;
import java.util.List;

import io.rong.imkit.IExtensionModule;
import io.rong.imkit.RongExtension;
import io.rong.imkit.RongIM;
import io.rong.imkit.emoticon.IEmoticonTab;
import io.rong.imkit.plugin.IPluginModule;
import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.Message;

public class MRedPackgeExtensionModule implements IExtensionModule {

    private String mTargetId;

    @Override
    public void onInit(String s) {
        RongIM.registerMessageType(RCRedPackageMessage.class);
        RongIM.registerMessageTemplate(new RCRedPackageMessageProvider());
    }

    @Override
    public void onConnect(String s) {

    }

    @Override
    public void onAttachedToExtension(RongExtension rongExtension) {
        mTargetId = rongExtension.getTargetId();
    }

    @Override
    public void onDetachedFromExtension() {

    }

    @Override
    public void onReceivedMessage(Message message) {

    }

    @Override
    public List<IPluginModule> getPluginModules(Conversation.ConversationType conversationType) {
        List<IPluginModule> pluginModules = new ArrayList<>();
        if (conversationType.equals(Conversation.ConversationType.GROUP)) {
            pluginModules.add(new MGroupRedPackagePlugin());
        } else if (conversationType.equals(Conversation.ConversationType.PRIVATE) && q.c(CurrentUser.getUserId()) && !CurrentUser.getUserId().equals(this.mTargetId)) {
            pluginModules.add(new MSingleRedPackagePlugin());
        }
        return pluginModules;
    }

    @Override
    public List<IEmoticonTab> getEmoticonTabs() {
        return null;
    }

    @Override
    public void onDisconnect() {

    }

}
