package com.getbubblenow.android.viewmodel;

import android.content.Context;

import com.getbubblenow.android.model.Network;
import com.getbubblenow.android.repository.DataRepository;
import com.getbubblenow.android.model.ObservableTunnel;
import com.getbubblenow.android.resource.StatusResource;
import com.getbubblenow.android.util.UserStore;

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

public class MainViewModel extends ViewModel {
    public boolean isUserLoggedIn(Context context){
        return !UserStore.USER_TOKEN_DEFAULT_VALUE.equals(UserStore.getInstance(context).getToken());
    }

    public ObservableTunnel getTunnel(Context context, boolean stateTunnel) {
        return DataRepository.getRepositoryInstance().getTunnel(context,stateTunnel);
    }

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

    public MutableLiveData<Boolean> connectWithPermission(final boolean checked , Context context) {
        return DataRepository.getRepositoryInstance().connectWithPermission(checked,context);
    }

    public MutableLiveData<Boolean> connect(final Boolean checked , Context context) {
        return DataRepository.getRepositoryInstance().connect(checked,context);
    }

    public boolean isVPNConnected(Context context, boolean connectionStateFlag) {
        return DataRepository.getRepositoryInstance().isVPNConnected(context,connectionStateFlag);
    }

    public String getHostname(Context context){
        return DataRepository.getRepositoryInstance().getHostname(context);
    }

    public void removeSharedPreferences(Context context){
        DataRepository.getRepositoryInstance().removeSharedPreferences(context);
    }

    public void deleteTunnel(Context context){
        DataRepository.getRepositoryInstance().deleteTunnel(context);
    }

    public String getToken(Context context) {
        return UserStore.getInstance(context).getToken();
    }

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

    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 isHaveSageURL(Context context){
        return !UserStore.getInstance(context).getSageURL().isEmpty();
    }

    public boolean isHaveHostName(Context context){
        return !UserStore.getInstance(context).getHostname().isEmpty();
    }

    public String getSageURL(Context context){
        return UserStore.getInstance(context).getSageURL();
    }

    public void setConfig(String config, Context context){
        UserStore.getInstance(context).setConfig(config);
    }

    public MutableLiveData<StatusResource<byte[]>> getCertificateData(Context context) {
        return DataRepository.getRepositoryInstance().getCertificateData(context);
    }

    public MutableLiveData<StatusResource<Network>> getNetworkStatusLiveData(){
        return DataRepository.getRepositoryInstance().getNetworkStatusLiveData();
    }

    public  MutableLiveData<Long> getProgressLiveData(){
        return DataRepository.getRepositoryInstance().getProgressLiveData();
    }

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

    public String getSageHostname(Context context){
        return UserStore.getInstance(context).getSageHostname();
    }

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

    public String getSageToken(Context context){
        return UserStore.getInstance(context).getSageToken();
    }

    public String getHostNameForAccount(Context context){
        return UserStore.getInstance(context).getHostNameForAccount();
    }
}
