package com.getbubblenow.android.viewmodel;

import android.content.Context;

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

import java.util.Locale;

import java.util.List;

import androidx.lifecycle.MutableLiveData;

public class MainViewModel extends BaseViewModel {

    public void clearCredentials(final Context context) {
        CredentialRepository.getInstance(context).clear();
    }

    public void disposeBubbleCheck() {
        DataRepository.getRepositoryInstance().disposeBubbleCheck();
    }

    public void disposeProgress() {
        DataRepository.getRepositoryInstance().disposeProgress();
    }

    public boolean isUserLoggedInToSage(final Context context) {
        return !UserStore.SAGE_TOKEN_DEFAULT_VALUE.equals(UserStore.getInstance(context).getSageToken());
    }

    public MutableLiveData<Boolean> updatePreAuthLocalization(final Context context, final Locale locale) {
        return RestringMessageRepository.getInstance().updatePreAuthLocalization(context, locale);
    }

    public MutableLiveData<Boolean> updatePostAuthLocalization(final Context context, final Locale locale) {
        return RestringMessageRepository.getInstance().updatePostAuthLocalization(context, locale);
    }

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

    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(){
        DataRepository.getRepositoryInstance().deleteTunnel();
    }

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

    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 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<List<Network>>> checkBubbleOnce(final Context context) {
        return DataRepository.getRepositoryInstance().checkBubbleOnce(context);
    }

    public MutableLiveData<StatusResource<List<Network>>> checkBubbleContinuously(final Context context) {
        return DataRepository.getRepositoryInstance().checkBubbleContinuously(context);
    }

    public MutableLiveData<StatusResource<byte[]>> loginToNode(final Context context, final String uuid) {
        return DataRepository.getRepositoryInstance().loginToNode(context, uuid);
    }

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

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

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

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

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

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