package corp.wmsoft.android.lib.mvpc.interactor;

import corp.wmsoft.android.lib.mvpc.util.IMVPCSchedulerProvider;
import rx.Observable;
import rx.Observer;
import rx.Subscription;
import rx.functions.Action1;


/**
 * Abstract class for a Use Case (Interactor in terms of Clean Architecture).
 * This interface represents a execution unit for different use cases (this means any use case
 * in the application should implement this contract).
 *
 * By convention each UseCase implementation will return the result using a {@link rx.Subscriber}
 * that will execute its job in a background thread and will post the result in the UI thread.
 *
 * @param <Q> the request type
 * @param <T> the response type
 */

public abstract class MVPCUseCase<Q extends MVPCUseCase.RequestValues, T> {

    /**/
    private final IMVPCSchedulerProvider mMVPCSchedulerProvider;
    /**/
    private Q mRequestValues;


    public MVPCUseCase(IMVPCSchedulerProvider schedulerProvider) {
        this.mMVPCSchedulerProvider = schedulerProvider;
    }

    /**
     *
     */
    public void setRequestValues(Q requestValues) {
        mRequestValues = requestValues;
    }

    /**
     *
     */
    public Q getRequestValues() {
        return mRequestValues;
    }

    /**
     * Builds an {@link rx.Observable} which will be used when executing the current {@link MVPCUseCase}.
     */
    public abstract Observable<T> buildUseCaseObservable();

    /**
     * Executes the current use case.
     *
     * @param useCaseSubscriber The guy who will be listen to the observable build with {@link #buildUseCaseObservable()}.
     */
    public Subscription execute(Observer<? super T> useCaseSubscriber) {
        return this.buildUseCaseObservable()
                .subscribeOn(mMVPCSchedulerProvider.io())
                .observeOn(mMVPCSchedulerProvider.ui())
                .subscribe(useCaseSubscriber);
    }

    public Subscription execute(final Action1<? super T> useCaseOnNext) {
        return this.buildUseCaseObservable()
                .subscribeOn(mMVPCSchedulerProvider.io())
                .observeOn(mMVPCSchedulerProvider.ui())
                .subscribe(useCaseOnNext);
    }

    /**
     * Data passed to a request.
     */
    public static class RequestValues {  }
}

@@ -859,47 +859,8 @@
 er;%0A
-    /**/%0A    private Q mRequestValues;%0A
 %0A%0A  
@@ -992,225 +992,8 @@
  %7D%0A%0A
-    /**%0A     *%0A     */%0A    public void setRequestValues(Q requestValues) %7B%0A        mRequestValues = requestValues;%0A    %7D%0A%0A    /**%0A     *%0A     */%0A    public Q getRequestValues() %7B%0A        return mRequestValues;%0A    %7D%0A%0A
     
@@ -1167,16 +1167,31 @@
 ervable(
+Q requestValues
 );%0A%0A    
@@ -1358,16 +1358,17 @@
 ervable(
+Q
 )%7D.%0A    
@@ -1403,16 +1403,33 @@
 execute(
+Q requestValues, 
 Observer
@@ -1496,32 +1496,45 @@
 eCaseObservable(
+requestValues
 )%0A              
@@ -1719,16 +1719,33 @@
 execute(
+Q requestValues, 
 final Ac
@@ -1821,16 +1821,29 @@
 ervable(
+requestValues
 )%0A      

set use case request values as parameters