/*
 * The MIT License
 *
 * Copyright (c) 2013-2016 reark project contributors
 *
 * https://github.com/reark/reark/graphs/contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package io.reark.reark.data;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import io.reark.reark.utils.Preconditions;

public class DataStreamNotification<T> {

    private enum Type {
        FETCHING_START,
        FETCHING_COMPLETED,
        FETCHING_ERROR,
        ON_NEXT
    }

    @NonNull
    final private Type type;
    final private T value;
    final private Throwable error;

    private DataStreamNotification(@NonNull Type type, T value, Throwable error) {
        Preconditions.checkNotNull(type, "Type cannot be null.");

        this.type = type;
        this.value = value;
        this.error = error;
    }

    @Nullable
    public T getValue() {
        return value;
    }

    @NonNull
    public static<T> DataStreamNotification<T> fetchingStart() {
        return new DataStreamNotification<>(Type.FETCHING_START, null, null);
    }

    @NonNull
    public static<T> DataStreamNotification<T> onNext(T value) {
        return new DataStreamNotification<>(Type.ON_NEXT, value, null);
    }

    @NonNull
    public static<T> DataStreamNotification<T> fetchingCompleted() {
        return new DataStreamNotification<>(Type.FETCHING_COMPLETED, null, null);
    }

    @NonNull
    public static<T> DataStreamNotification<T> fetchingError() {
        return new DataStreamNotification<>(Type.FETCHING_ERROR, null, null);
    }

    public boolean isFetchingStart() {
        return type.equals(Type.FETCHING_START);
    }

    public boolean isOnNext() {
        return type.equals(Type.ON_NEXT);
    }

    public boolean isFetchingCompleted() {
        return type.equals(Type.FETCHING_COMPLETED);
    }

    public boolean isFetchingError() {
        return type.equals(Type.FETCHING_ERROR);
    }

    @Nullable
    public Throwable getError() {
        return error;
    }
}

@@ -1417,22 +1417,21 @@
 %7B%0A%0A    p
-rivate
+ublic
  enum Ty
@@ -1551,30 +1551,24 @@
 ull%0A    
-final 
 private 
 Type typ
@@ -1559,16 +1559,22 @@
 private 
+final 
 Type typ
@@ -1576,25 +1576,34 @@
 e type;%0A
+%0A
     
-final
+@Nullable%0A   
  private
@@ -1603,16 +1603,22 @@
 private 
+final 
 T value;
@@ -1622,17 +1622,26 @@
 ue;%0A
+%0A
     
-final
+@Nullable%0A   
  pri
@@ -1645,16 +1645,22 @@
 private 
+final 
 Throwabl
@@ -1728,16 +1728,36 @@
 pe, 
-T value,
+@Nullable T value, @Nullable
  Thr
@@ -1938,62 +1938,208 @@
   @N
-ullable%0A    public T getValue() %7B%0A        return value
+onNull%0A    public Type getType() %7B%0A        return type;%0A    %7D%0A%0A    @Nullable%0A    public T getValue() %7B%0A        return value;%0A    %7D%0A%0A    @Nullable%0A    public Throwable getError() %7B%0A        return error
 ;%0A  
@@ -3173,84 +3173,7 @@
    %7D
-%0A%0A    @Nullable%0A    public Throwable getError() %7B%0A        return error;%0A    %7D
 %0A%7D%0A

Add getter for datastream notification type