package com.sonic.pigeon.lib.client;

import com.alibaba.fastjson.TypeReference;
import com.sonic.common.AppRuntime;
import com.sonic.common.rpc.Result;
import com.sonic.common.rpc.RpcClient;
import com.sonic.pigeon.lib.input.CreateConversationInput;
import com.sonic.pigeon.lib.input.UpdateConversationInput;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author code
 */
@Slf4j
@Service
public class ImConversationClient {

    private static final String IM_CONVERSATION_CREATE = "/api/im-conversation/create";
    private static final String IM_CONVERSATION_UPDATE = "/api/im-conversation/update";

    private RpcClient rpcClient;
    private String host;

    public ImConversationClient(RpcClient rpcClient, AppRuntime appRuntime) {
        this.rpcClient = rpcClient;
        switch (appRuntime.getEnv()) {
            case dev:
                this.host = "http://localhost:8080";
                break;
            case local:
                this.host = "http://localhost:8080";
                break;
            case test:
                this.host = "http://test-pigeon-svc:8080";
                break;
            case product:
            default:
                this.host = "http://prod-pigeon-svc:8080";
        }
    }




    /**
     * 新建会话扩展字段
     * @param input
     * @return
     */
    public void createConversation(CreateConversationInput input) {
        rpcClient.post(host + IM_CONVERSATION_CREATE, input, new TypeReference<Result<Void>>(){});
    }

    /**
     * 更新会话扩展字段
     * @param input
     * @return
     */
    public void updateConversation(UpdateConversationInput input) {
        rpcClient.post(host + IM_CONVERSATION_UPDATE, input, new TypeReference<Result<Void>>(){});
    }

}
