package com.wecloud.im.sdk.internal;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import com.wecloud.im.sdk.common.HttpMethod;
import com.wecloud.im.sdk.common.RequestMessage;
import com.wecloud.im.sdk.model.SetConversationDoNotDisturbRequest;
import com.wecloud.im.sdk.model.SetConversationTopRequest;

import static com.wecloud.im.sdk.ResourcePathConstants.REGISTER_CLIENT_URL;
import static com.wecloud.im.sdk.utils.CodingUtils.assertParameterNotNull;

/**
 * client
 * @Author luozh
 * @Date 2022年04月13日 15:26
 * @Version 1.0
 */
public class WecloudImConversationOperation extends WecloudImOperation {

    public WecloudImConversationOperation(URL apiDomain, String appKey, String appSecret) {
        super(apiDomain, appKey, appSecret);
    }

    /**
     * 设置会话置顶
     * @Author luozh
     * @Date 2022年04月26日 03:57:51
     * @param setConversationTopRequest
     * @Return
     */
    public Boolean setConversationTop(SetConversationTopRequest setConversationTopRequest) {
        String userId = setConversationTopRequest.getUserId();
        Long conversationId = setConversationTopRequest.getConversationId();
        Boolean top = setConversationTopRequest.getTop();
        // 参数校验
        assertParameterNotNull(userId, "userId");
        assertParameterNotNull(conversationId, "conversationId");
        assertParameterNotNull(top, "top");
        // 校验通过 构建参数
        Map<String, String> param = new HashMap<>();
        param.put("clientId", userId);
        param.put("conversationId", conversationId.toString());
        param.put("top", top.toString());
        // 发送请求
        RequestMessage request = new WecloudRequestMessageBuilder().setEndpoint(REGISTER_CLIENT_URL)
                .setMethod(HttpMethod.POST).setParameters(param)
                .setOriginalRequest(setConversationTopRequest).build();

        doOperation(request);
        return true;
    }

    /**
     * 设置会话免打扰
     * @Author luozh
     * @Date 2022年04月26日 03:58:10
     * @param setConversationDoNotDisturbRequest 设置会话免打扰
     * @Return
     */
    public Boolean setConversationDoNotDisturb(SetConversationDoNotDisturbRequest setConversationDoNotDisturbRequest) {
        String userId = setConversationDoNotDisturbRequest.getUserId();
        Long conversationId = setConversationDoNotDisturbRequest.getConversationId();
        Boolean doNotDisturb = setConversationDoNotDisturbRequest.getDoNotDisturb();
        // 参数校验
        assertParameterNotNull(userId, "userId");
        assertParameterNotNull(conversationId, "conversationId");
        assertParameterNotNull(doNotDisturb, "doNotDisturb");
        // 校验通过 构建参数
        Map<String, String> param = new HashMap<>();
        param.put("clientId", userId);
        param.put("conversationId", conversationId.toString());
        param.put("doNotDisturb", doNotDisturb.toString());
        // 发送请求
        RequestMessage request = new WecloudRequestMessageBuilder().setEndpoint(REGISTER_CLIENT_URL)
                .setMethod(HttpMethod.POST).setParameters(param)
                .setOriginalRequest(setConversationDoNotDisturbRequest).build();

        doOperation(request);
        return true;
    }
}
