package com.sonic.bear.lib.client;

import com.alibaba.fastjson.TypeReference;
import com.sonic.bear.lib.input.CompleteUserInfoInput;
import com.sonic.bear.lib.input.EditUserInfoInput;
import com.sonic.bear.lib.input.UserIdInput;
import com.sonic.common.AppRuntime;
import com.sonic.common.rpc.Result;
import com.sonic.common.rpc.RpcClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

    private static final String URI_COMPLETE_USER_INFO = "/api/user/complete-user-info";

    private static final String URI_EDIT_USER_INFO = "/api/user/edit-user-info";

    private static final String URI_DEL_ACCOUNT = "/api/user/del-account";



    private RpcClient rpcClient;
    private String host;

    public UserSetClient(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-bear-svc:8080";
                break;
            case product:
            default:
                this.host = "http://prod-bear-svc:8080";
        }
    }


    /**
     * 完善用户基础信息
     * @param input
     * @return
     */
    public void completeUserInfo(CompleteUserInfoInput input) {
        rpcClient.post(host + URI_COMPLETE_USER_INFO, input, new TypeReference<Result<Void>>(){});
    }

    /**
     * 编辑用户基础信息
     * @param input
     * @return
     */
    public void editUserInfo(EditUserInfoInput input) {
        rpcClient.post(host + URI_EDIT_USER_INFO, input, new TypeReference<Result<Void>>(){});
    }

    /**
     * 编辑用户基础信息
     * @param userId
     * @return
     */
    public void delAccount(Long userId) {
        UserIdInput input = UserIdInput.builder()
                .userId(userId)
                .build();
        rpcClient.post(host + URI_DEL_ACCOUNT, input, new TypeReference<Result<Void>>(){});
    }

}
