package io.oldering.tvfoot.red.app.domain.match;

import android.databinding.ObservableBoolean;
import android.databinding.ObservableField;
import io.oldering.tvfoot.red.app.domain.match.state.MatchViewState;
import io.oldering.tvfoot.red.app.domain.matches.BroadcastersAdapter;
import javax.inject.Inject;

import static io.oldering.tvfoot.red.app.common.PreConditions.checkNotNull;

public class MatchViewModel {
  private final BroadcastersAdapter broadcastersAdapter;
  public ObservableBoolean isLoading = new ObservableBoolean();
  public ObservableBoolean hasError = new ObservableBoolean(false);
  public ObservableBoolean hasData = new ObservableBoolean(false);
  public ObservableBoolean shouldNotifyMatchStart = new ObservableBoolean(false);
  public ObservableField<MatchDisplayable> match = new ObservableField<>();
  public ObservableField<String> errorMessage = new ObservableField<>();

  @Inject MatchViewModel(BroadcastersAdapter broadcastersAdapter) {
    this.broadcastersAdapter = broadcastersAdapter;
  }

  @SuppressWarnings("ThrowableResultOfMethodCallIgnored") void updateFromState(
      MatchViewState state) {
    isLoading.set(state.loading());
    hasError.set(state.error() != null);
    hasData.set(state.match() != null);
    shouldNotifyMatchStart.set(state.shouldNotifyMatchStart());

    if (hasError.get()) {
      Throwable error = checkNotNull(state.error(), "state error is null");
      errorMessage.set(error.toString());
    }
    if (hasData.get()) {
      if (match.get() == null || !match.get().equals(state.match())) {
        match.set(state.match());
        broadcastersAdapter.addAll(match.get().broadcasters());
      }
    }
  }
}

@@ -1488,22 +1488,23 @@
 et()
-) %7B
+ && //
 %0A      
-if (
+  
 matc
@@ -1562,26 +1562,24 @@
 ))) %7B%0A      
- 
- 
 match.set(st
@@ -1588,26 +1588,24 @@
 e.match());%0A
-  
       broadc
@@ -1658,24 +1658,18 @@
 ));%0A
-      %7D%0A
     %7D%0A
-
   %7D%0A%7D%0A
+%7D%0A

simplified if statement