package com.getbubblenow.android.viewmodel;

import android.content.Context;

import com.getbubblenow.android.repository.DataRepository;
import com.getbubblenow.android.resource.StatusResource;

import java.util.List;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

public class LoginViewModel extends ViewModel {

    @Override protected void onCleared() {
        super.onCleared();
        DataRepository.getRepositoryInstance().clearDisposable();
    }

    public void buildRepositoryInstance(Context context, String url){
        DataRepository.buildRepositoryInstance(context,url);
    }

    public void buildClientService(String url){
        DataRepository.getRepositoryInstance().buildClientService(url);
    }

    public void setHostName(Context context, String hostname){
        DataRepository.getRepositoryInstance().setHostName(context,hostname);
    }

    public MutableLiveData<StatusResource<byte[]>> login (Context context, String username, String password){
       return DataRepository.getRepositoryInstance().login(context, username, password);
    }

    public MutableLiveData<StatusResource<String>> getConfig(Context context){
        return DataRepository.getRepositoryInstance().getConfig(context);
    }

    public MutableLiveData<StatusResource<Object>> createTunnel(Context context, String dataConfig){
        return DataRepository.getRepositoryInstance().createTunnel(context, dataConfig);
    }

    public boolean isHaveCertificate(Context context){
        return DataRepository.getRepositoryInstance().isHaveCertificate(context);
    }

    public boolean checkRepositoryInstance(){
        return DataRepository.getRepositoryInstance() == null;
    }
}
