package com.ym.service.Impl;

import com.ym.service.ChatroomService;
import io.rong.RongCloud;
import io.rong.methods.chatroom.Chatroom;
import io.rong.methods.chatroom.block.Block;
import io.rong.methods.chatroom.demotion.Demotion;
import io.rong.methods.chatroom.distribute.Distribute;
import io.rong.methods.chatroom.keepalive.Keepalive;
import io.rong.methods.chatroom.mute.MuteMembers;
import io.rong.methods.chatroom.whitelist.Whitelist;
import io.rong.methods.sensitive.Wordfilter;
import io.rong.models.Result;
import io.rong.models.chatroom.ChatroomMember;
import io.rong.models.chatroom.ChatroomModel;
import io.rong.models.response.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ChatroomServiceImpl implements ChatroomService {
    @Value("${cn.rongcloud.im.appkey}")
    private String appKey;
    @Value("${cn.rongcloud.im.secret}")
    private String appSecret;

    private Chatroom getChatroom(){
        RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret);
        return new Chatroom(appKey,appSecret,rongCloud);
    }
    private Block getBlock(){
        return new Block(appKey,appSecret);
    }
    private MuteMembers getMuteMembers(){
        RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret);
        return new MuteMembers(appKey,appSecret,rongCloud);
    }
    private Whitelist getWhitelist(){
        return new Whitelist(appKey,appSecret);
    }
    private Keepalive getKeepalive(){
        return new Keepalive(appKey,appSecret);
    }
    private Distribute getDistribute(){
        return new Distribute(appKey,appSecret);
    }
    private Demotion getDemotion(){
        return new Demotion(appKey,appSecret);
    }
    private Wordfilter getWordfilter(){
        return new Wordfilter(appKey,appSecret);
    }

    @Override
    public Result chatroomCreate(ChatroomModel[] chatroomModels) throws Exception {
        return getChatroom().create(chatroomModels);
    }

    @Override
    public Result chatroomDestory(ChatroomModel chatroomModel) throws Exception {
        return getChatroom().destroy(chatroomModel);
    }

    @Override
    public Result chatroomGet(ChatroomModel chatroomModel) throws Exception {
        return getChatroom().get(chatroomModel);
    }

    @Override
    public CheckChatRoomUserResult chatroomIsExit(ChatroomMember chatroomMember) throws Exception {
        return getChatroom().isExist(chatroomMember);
    }

    @Override
    public Result chatroomBlockAdd(ChatroomModel chatroomModel) throws Exception {
        return getBlock().add(chatroomModel);
    }

    @Override
    public Result chatroomBlockRemove(ChatroomModel chatroomModel) throws Exception {
        return getBlock().remove(chatroomModel);
    }

    @Override
    public Result chatroomBlockGetList(String chatroomId) throws Exception {
        return getBlock().getList(chatroomId);
    }

    @Override
    public ResponseResult chatroomMuteMembersAdd(ChatroomModel chatroomModel) throws Exception {
        return getMuteMembers().add(chatroomModel);
    }

    @Override
    public ResponseResult chatroomMuteMembersRemove(ChatroomModel chatroomModel) throws Exception {
        return getMuteMembers().remove(chatroomModel);
    }

    @Override
    public ListGagChatroomUserResult chatroomMuteMembersGetList(ChatroomModel chatroomModel) throws Exception {
        return getMuteMembers().getList(chatroomModel);
    }

    @Override
    public ChatroomDemotionMsgResult demotionGetList() throws Exception {
        return getDemotion().getList();
    }

    @Override
    public ResponseResult demotionRemove(String[] objectNames) throws Exception {
        return getDemotion().remove(objectNames);
    }

    @Override
    public ResponseResult demotionAdd(String[] objectNames) throws Exception {
        return getDemotion().add(objectNames);
    }

    @Override
    public ResponseResult distributeStop(ChatroomModel chatroomModel) throws Exception {
        return getDistribute().stop(chatroomModel);
    }

    @Override
    public ResponseResult distributeResume(ChatroomModel chatroomModel) throws Exception {
        return getDistribute().resume(chatroomModel);
    }

    @Override
    public ResponseResult keepAliveAdd(ChatroomModel chatroomModel) throws Exception {
        return getKeepalive().add(chatroomModel);
    }

    @Override
    public ResponseResult keepAliveRemove(ChatroomModel chatroomModel) throws Exception {
        return getKeepalive().remove(chatroomModel);
    }

    @Override
    public ChatroomKeepaliveResult keepAliveGetList() throws Exception {
        return getKeepalive().getList();
    }

    @Override
    public ResponseResult whitelistUserAdd(ChatroomModel chatroomModel) throws Exception {
        return getWhitelist().user.add(chatroomModel);
    }

    @Override
    public ResponseResult whitelistUserRemove(ChatroomModel chatroomModel) throws Exception {
        return getWhitelist().user.remove(chatroomModel);
    }

    @Override
    public Result whitelistUserGetList(ChatroomModel chatroomModel) throws Exception {
        return getWhitelist().user.getList(chatroomModel);
    }

    @Override
    public ResponseResult whitelistMessageAdd(String[] objectNames) throws Exception {
        return getWhitelist().message.add(objectNames);
    }

    @Override
    public ResponseResult whitelistMessageRemove(String[] objectNames) throws Exception {
        return getWhitelist().message.remove(objectNames);
    }

    @Override
    public ChatroomWhitelistMsgResult whitelistMessageGetList() throws Exception {
        return getWhitelist().message.getList();
    }

    @Override
    public ResponseResult sensitiveAdd(String word) throws Exception {
        return getWordfilter().add(word);
    }

    @Override
    public ResponseResult sensitiveRemove(String word) throws Exception {
        return getWordfilter().remove(word);
    }

    @Override
    public ListWordfilterResult sensitiveGetList() throws Exception {
        return getWordfilter().getList();
    }
}
