package com.malk.service.dingtalk.impl;

import com.malk.server.dingtalk.DDR;
import com.malk.service.dingtalk.DDClient_Group;
import com.malk.utils.UtilMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@Slf4j
public class DDImplClient_Group implements DDClient_Group {

    @Override
    public Map createGroup(String access_token,Map body) {
        Map param = UtilMap.map("access_token", access_token);
        return (Map) DDR.doPost("https://oapi.dingtalk.com/topapi/im/chat/scenegroup/create", null, param, body).getResult();
    }

    @Override
    public String createGroupByTemp(String access_token, String title, String template_id, String owner_user_id, String user_ids) {
        Map body = UtilMap.map("title, template_id, owner_user_id, user_ids",title,template_id,owner_user_id,user_ids);
        return String.valueOf(createGroup(access_token,body).get("open_conversation_id"));
    }

    @Override
    public Boolean addGroupUser(String access_token, String open_conversation_id, String user_ids) {
        Map param = UtilMap.map("access_token", access_token);
        Map body = UtilMap.map("open_conversation_id, user_ids",open_conversation_id,user_ids);
        return DDR.doPost("https://oapi.dingtalk.com/topapi/im/chat/scenegroup/member/add", null, param, body).isSuccess();
    }

    @Override
    public Boolean delGroupUser(String access_token, String open_conversation_id, String user_ids) {
        Map param = UtilMap.map("access_token", access_token);
        Map body = UtilMap.map("open_conversation_id, user_ids",open_conversation_id,user_ids);
        return DDR.doPost("https://oapi.dingtalk.com/topapi/im/chat/scenegroup/member/delete", null, param, body).isSuccess();
    }
}
