package com.keao.edu.im.service.Impl;

import com.keao.edu.im.mec.im.IMHelper;
import com.keao.edu.im.service.UserService;
import io.rong.RongCloud;
import io.rong.methods.user.User;
import io.rong.methods.user.blacklist.Blacklist;
import io.rong.methods.user.block.Block;
import io.rong.methods.user.mute.MuteChatrooms;
import io.rong.methods.user.mute.MuteGroups;
import io.rong.methods.user.tag.Tag;
import io.rong.models.Result;
import io.rong.models.chatroom.ChatroomModel;
import io.rong.models.group.GroupModel;
import io.rong.models.response.TokenResult;
import io.rong.models.user.BatchTagModel;
import io.rong.models.user.GetTagModel;
import io.rong.models.user.TagModel;
import io.rong.models.user.UserModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * Created by weiqinxiao on 2019/2/25.
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Value("${cn.rongcloud.im.appkey}")
    private String appKey;
    @Value("${cn.rongcloud.im.secret}")
    private String appSecret;

    @Autowired
    IMHelper imHelper;

    private User getUser(){
        RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret);
        return rongCloud.user;
    }
    private Blacklist getBlacklist(){
        RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret);
        return new Blacklist(appKey,appSecret,rongCloud);
    }
    private Block getBlock(){
        RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret);
        return new Block(appKey,appSecret,rongCloud);
    }
    private Tag getTag(){
        RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret);
        return new Tag(appKey,appSecret,rongCloud);
    }
    private MuteGroups getMuteGroups(){
        RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret);
        return new MuteGroups(appKey,appSecret,rongCloud);
    }
    private MuteChatrooms getMuteChatrooms(){
        RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret);
        return new MuteChatrooms(appKey,appSecret,rongCloud);
    }

    @Override
    public TokenResult register(UserModel userModel) throws Exception {
        return getUser().register(userModel);
    }

    @Override
    public Result update(UserModel userModel) throws Exception {
        return getUser().update(userModel);
    }

    @Override
    public Result blackListAdd(UserModel userModel) throws Exception {
        return getBlacklist().add(userModel);
    }

    @Override
    public Result blackListRemove(UserModel userModel) throws Exception {
        return getBlacklist().remove(userModel);
    }

    @Override
    public Result blackListGetList(UserModel userModel) throws Exception {
        return getBlacklist().getList(userModel);
    }

    @Override
    public Result blockAdd(UserModel userModel) throws Exception {
        return getBlock().add(userModel);
    }

    @Override
    public Result blockRemove(String userId) throws Exception {
        return getBlock().remove(userId);
    }

    @Override
    public Result blockGetList() throws Exception {
        return getBlock().getList();
    }

    @Override
    public Result tagSet(TagModel tagModel) throws Exception {
        return getTag().set(tagModel);
    }

    @Override
    public Result tagBatchSet(BatchTagModel batchTagModel) throws Exception {
        return getTag().batchSet(batchTagModel);
    }

    @Override
    public Result tagGet(GetTagModel getTagModel) throws Exception {
        return getTag().get(getTagModel);
    }

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

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

    @Override
    public Result muteGroupsGetList() throws Exception {
        return getMuteGroups().getList();
    }

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

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

    @Override
    public Result muteChatroomsGetList() throws Exception {
        return getMuteChatrooms().getList();
    }
}
