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.CreateImUserInput;
import com.sonic.pigeon.lib.input.EditImUserInput;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

    private static final String IM_USER_CREATE = "/api/im-user/create";

    private static final String IM_USER_EDIT = "/api/im-user/edit";

    private RpcClient rpcClient;
    private String host;

    public ImUserClient(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";
        }
    }


    /**
     * 创建IM用户
     * @param input
     * @return
     */
    public void createImUser(CreateImUserInput input) {
        rpcClient.post(host + IM_USER_CREATE, input, new TypeReference<Result<Void>>(){});
    }

    /**
     * 编辑IM用户
     * @param input
     * @return
     */
    public void editImUser(EditImUserInput input) {
        rpcClient.post(host + IM_USER_EDIT, input, new TypeReference<Result<Void>>(){});
    }

}
