package com.siu.android.volleyball.complete;

import com.android.volley.NetworkResponse;
import com.android.volley.Response;
import com.siu.android.volleyball.BallRequest;
import com.siu.android.volleyball.BallResponse;
import com.siu.android.volleyball.local.LocalRequestProcessor;
import com.siu.android.volleyball.network.NetworkRequestProcessor;
import com.siu.android.volleyball.response.ResponseListener;

/**
 * Created by lukas on 8/29/13.
 */
public abstract class CompleteRequest<T> extends BallRequest<T> {

    protected ResponseListener mResponseListener;

    public CompleteRequest(int method, String url, Response.ErrorListener errorListener) {
        super(method, url, errorListener);
    }

    protected CompleteRequest(int method, String url, ResponseListener<T> responseListener, Response.ErrorListener errorListener) {
        super(method, url, responseListener, errorListener);
    }


    /* LOCAL */

    @Override
    public boolean shouldProcessLocal() {
        return true;
    }

    @Override
    protected LocalRequestProcessor<T> createLocalRequestProcessor() {
        return new LocalRequestProcessor<T>() {
            @Override
            public T getLocalResponse() {
                return CompleteRequest.this.getLocalResponse();
            }

            @Override
            public void saveLocalResponse(T response) {
                CompleteRequest.this.saveLocalResponse(response);
            }
        };
    }

    protected abstract T getLocalResponse();

    public abstract void saveLocalResponse(T response);


    /* NETWORK */

    @Override
    public boolean shouldProcessNetwork() {
        return true;
    }

    @Override
    protected NetworkRequestProcessor createNetworkRequestProcessor() {
        return new NetworkRequestProcessor() {
            @Override
            public BallResponse<T> parseNetworkResponse(NetworkResponse networkResponse) {
                return parseBallNetworkResponse(networkResponse);
            }
        };
    }

    protected abstract BallResponse<T> parseBallNetworkResponse(NetworkResponse response);
}

@@ -1401,29 +1401,31 @@
 his.save
-Local
+Network
 Response
 (respons
@@ -1416,16 +1416,23 @@
 Response
+ToLocal
 (respons
@@ -1538,37 +1538,39 @@
 ct void save
-Local
+Network
 Response
 (T response)
@@ -1549,32 +1549,39 @@
 eNetworkResponse
+ToLocal
 (T response);%0A%0A%0A

Rename some methods.