// Path: ParallelRequests/app/src/main/java/itis/homework/parallelrequests/app/LoadingStateChangedEvent.java
// public class LoadingStateChangedEvent {
// 
//     private final RequestsState mState;
// 
//     private LoadingStateChangedEvent(RequestsState state) {
//         mState = state;
//     }
// 
//     @Produce
//     @NonNull
//     public static LoadingStateChangedEvent produce(@NonNull RequestsState state) {
//         return new LoadingStateChangedEvent(state);
//     }
// 
//     @NonNull
//     public RequestsState getState() {
//         return mState;
//     }
// }
// 
// Path: ParallelRequests/app/src/main/java/itis/homework/parallelrequests/app/Otto.java
// public class Otto {
// 
//     private final Bus mBus;
// 
//     private Otto(Bus bus) {
//         mBus = bus;
//     }
// 
//     @NonNull
//     public static Otto get() {
//         return Holder.INSTANCE;
//     }
// 
//     public void post(final @NonNull Object event) {
//         if (Looper.myLooper() == Looper.getMainLooper()) {
//             mBus.post(event);
//         }
//         else {
//             MainQueue.get().invoke(new Runnable() {
//                 @Override
//                 public void run() {
//                     mBus.post(event);
//                 }
//             });
//         }
//     }
// 
//     public void register(@NonNull Object object) {
//         mBus.register(object);
//     }
// 
//     public void unregister(@NonNull Object object) {
//         mBus.unregister(object);
//     }
// 
//     private static final class Holder {
//         public static final Otto INSTANCE = new Otto(new Bus());
//     }
// }


import java.util.ArrayList;
import java.util.List;
import itis.homework.parallelrequests.app.LoadingStateChangedEvent;
import itis.homework.parallelrequests.app.Otto;
                || requestType == RequestType.MESSAGES || requestType == RequestType.GROUPS)
                && (!mLoadedRequests.contains(RequestType.AUTH) || !mLoadedRequests.contains(RequestType.CONFIG))) {
            mIsFatalError = true;
            Otto.get().post(LoadingStateChangedEvent.produce(new RequestsState(RequestsState.GeneralState.ERROR)));
            return false;
        }

        if (requestType == RequestType.PHOTOS && !mLoadedRequests.contains(RequestType.MESSAGES)) {
            mIsFatalError = true;
            Otto.get().post(LoadingStateChangedEvent.produce(new RequestsState(RequestsState.GeneralState.ERROR)));
            return false;
        }

        mLoadingRequests.add(requestType);
        Otto.get().post(LoadingStateChangedEvent.produce(new RequestsState(RequestsState.GeneralState.LOADING,
                mLoadingRequests, mLoadedRequests)));
        return true;
    }

    @Override
    public void onRequestFinished(RequestType requestType) {
        if (mIsFatalError) {
            Otto.get().post(LoadingStateChangedEvent.produce(new RequestsState(RequestsState.GeneralState.ERROR)));
            return;
        }
        mLoadingRequests.remove(requestType);
        mLoadedRequests.add(requestType);
        if (mLoadedRequests.size() >= RequestType.values().length && mLoadingRequests.isEmpty()) {
            Otto.get().post(LoadingStateChangedEvent.produce(new RequestsState(RequestsState.GeneralState.LOADED)));
        } else {
// Path: ParallelRequests/app/src/main/java/itis/homework/parallelrequests/app/LoadingStateChangedEvent.java
// public class LoadingStateChangedEvent {
// 
//     private final RequestsState mState;
// 
//     private LoadingStateChangedEvent(RequestsState state) {
//         mState = state;
//     }
// 
//     @Produce
//     @NonNull
//     public static LoadingStateChangedEvent produce(@NonNull RequestsState state) {
//         return new LoadingStateChangedEvent(state);
//     }
// 
//     @NonNull
//     public RequestsState getState() {
//         return mState;
//     }
// }
// 
// Path: ParallelRequests/app/src/main/java/itis/homework/parallelrequests/app/Otto.java
// public class Otto {
// 
//     private final Bus mBus;
// 
//     private Otto(Bus bus) {
//         mBus = bus;
//     }
// 
//     @NonNull
//     public static Otto get() {
//         return Holder.INSTANCE;
//     }
// 
//     public void post(final @NonNull Object event) {
//         if (Looper.myLooper() == Looper.getMainLooper()) {
//             mBus.post(event);
//         }
//         else {
//             MainQueue.get().invoke(new Runnable() {
//                 @Override
//                 public void run() {
//                     mBus.post(event);
//                 }
//             });
//         }
//     }
// 
//     public void register(@NonNull Object object) {
//         mBus.register(object);
//     }
// 
//     public void unregister(@NonNull Object object) {
//         mBus.unregister(object);
//     }
// 
//     private static final class Holder {
//         public static final Otto INSTANCE = new Otto(new Bus());
//     }
// }


// Path: ParallelRequests/app/src/main/java/itis/homework/parallelrequests/network/RequestControllerImpl.java
import java.util.ArrayList;
import java.util.List;
import itis.homework.parallelrequests.app.LoadingStateChangedEvent;
import itis.homework.parallelrequests.app.Otto;

                || requestType == RequestType.MESSAGES || requestType == RequestType.GROUPS)
                && (!mLoadedRequests.contains(RequestType.AUTH) || !mLoadedRequests.contains(RequestType.CONFIG))) {
            mIsFatalError = true;
            Otto.get().post(LoadingStateChangedEvent.produce(new RequestsState(RequestsState.GeneralState.ERROR)));
            return false;
        }

        if (requestType == RequestType.PHOTOS && !mLoadedRequests.contains(RequestType.MESSAGES)) {
            mIsFatalError = true;
            Otto.get().post(LoadingStateChangedEvent.produce(new RequestsState(RequestsState.GeneralState.ERROR)));
            return false;
        }

        mLoadingRequests.add(requestType);
        Otto.get().post(LoadingStateChangedEvent.produce(new RequestsState(RequestsState.GeneralState.LOADING,
                mLoadingRequests, mLoadedRequests)));
        return true;
    }

    @Override
    public void onRequestFinished(RequestType requestType) {
        if (mIsFatalError) {
            Otto.get().post(LoadingStateChangedEvent.produce(new RequestsState(RequestsState.GeneralState.ERROR)));
            return;
        }
        mLoadingRequests.remove(requestType);
        mLoadedRequests.add(requestType);
        if (mLoadedRequests.size() >= RequestType.values().length && mLoadingRequests.isEmpty()) {
            Otto.get().post(LoadingStateChangedEvent.produce(new RequestsState(RequestsState.GeneralState.LOADED)));
        } else {
            Otto.get().post(LoadingStateChangedEvent.produce(new RequestsState(RequestsState.GeneralState.LOADING,