package com.ym.service.Impl;

import com.ym.service.GroupService;
import io.rong.RongCloud;
import io.rong.methods.conversation.Conversation;
import io.rong.methods.group.Group;
import io.rong.methods.group.mute.MuteAllMembers;
import io.rong.methods.group.mute.MuteMembers;
import io.rong.methods.group.mute.whitelist.User;
import io.rong.models.Result;
import io.rong.models.conversation.ConversationModel;
import io.rong.models.group.GroupModel;
import io.rong.models.group.UserGroup;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class GroupServiceImpl implements GroupService {

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

    private Group getGroup(){
        RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret);
        return new Group(appKey,appSecret,rongCloud);
    }
    private MuteMembers getMuteMembers(){
        RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret);
        return new MuteMembers(appKey,appSecret,rongCloud);
    }
    private MuteAllMembers getMuteAllMembers(){
        RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret);
        return new MuteAllMembers(appKey,appSecret,rongCloud);
    }
    private User getUser(){
        RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret);
        return new User(appKey,appSecret,rongCloud);
    }
    private Conversation getConversation(){
        return new Conversation(appKey,appSecret);
    }

    @Override
    public Result groupSync(UserGroup userGroup) throws Exception {
        return getGroup().sync(userGroup);
    }

    @Override
    public Result groupCreate(GroupModel groupModel) throws Exception {
        return getGroup().create(groupModel);
    }

    @Override
    public Result groupGet(GroupModel groupModel) throws Exception {
        return getGroup().get(groupModel);
    }

    @Override
    public Result groupUpdate(GroupModel groupModel) throws Exception {
        return getGroup().update(groupModel);
    }

    @Override
    public Result groupJoin(GroupModel groupModel) throws Exception {
        return getGroup().join(groupModel);
    }

    @Override
    public Result groupQuit(GroupModel groupModel) throws Exception {
        return getGroup().quit(groupModel);
    }

    @Override
    public Result groupDismiss(GroupModel groupModel) throws Exception {
        return getGroup().dismiss(groupModel);
    }

    @Override
    public Result muteMembersAdd(GroupModel groupModel) throws Exception {
        return getMuteMembers().add(groupModel);
    }

    @Override
    public Result muteMembersRemove(GroupModel groupModel) throws Exception {
        return getMuteMembers().remove(groupModel);
    }

    @Override
    public Result muteMembersGetList(String groupId) throws Exception {
        return getMuteMembers().getList(groupId);
    }

    @Override
    public Result muteAllMembersAdd(String[] groupIds) throws Exception {
        return getMuteAllMembers().add(groupIds);
    }

    @Override
    public Result muteAllMembersRemove(String[] groupIds) throws Exception {
        return getMuteAllMembers().remove(groupIds);
    }

    @Override
    public Result muteAllMembersGetList() throws Exception {
        return getMuteAllMembers().getList();
    }

    @Override
    public Result muteWhiteAdd(GroupModel groupModel) throws Exception {
        return getUser().add(groupModel);
    }

    @Override
    public Result muteWhiteRemove(GroupModel groupModel) throws Exception {
        return getUser().remove(groupModel);
    }

    @Override
    public Result muteWhiteGetList(String groupId) throws Exception {
        return getUser().getList(groupId);
    }

    @Override
    public Result conversationMute(ConversationModel conversationModel) throws Exception {
        return getConversation().mute(conversationModel);
    }

    @Override
    public Result conversationUnmute(ConversationModel conversationModel) throws Exception {
        return getConversation().unMute(conversationModel);
    }
}
