package info.izumin.android.bletia.core;

import java.util.UUID;

import info.izumin.android.bletia.core.action.AbstractAction;
import info.izumin.android.bletia.core.action.AbstractEnableNotificationAction;
import info.izumin.android.bletia.core.action.AbstractReadCharacteristicAction;
import info.izumin.android.bletia.core.action.AbstractReadDescriptorAction;
import info.izumin.android.bletia.core.action.AbstractReadRemoteRssiAction;
import info.izumin.android.bletia.core.action.AbstractWriteCharacteristicAction;
import info.izumin.android.bletia.core.action.AbstractWriteDescriptorAction;

/**
 * Created by izumin on 10/3/15.
 */
public class StateContainer {
    private ActionQueue<AbstractReadCharacteristicAction, UUID> mReadCharacteristicActionQueue;
    private ActionQueue<AbstractWriteCharacteristicAction, UUID> mWriteCharacteristicActionQueue;
    private ActionQueue<AbstractReadDescriptorAction, UUID> mReadDescriptorActionQueue;
    private ActionQueue<AbstractWriteDescriptorAction, UUID> mWriteDescriptorActionQueue;
    private ActionQueue<AbstractEnableNotificationAction, UUID> mEnableNotificationActionQueue;
    private ActionQueue<AbstractReadRemoteRssiAction, Void> mReadRemoteRssiActionQueue;

    public StateContainer() {
        mReadCharacteristicActionQueue = new ActionQueue<>();
        mWriteCharacteristicActionQueue = new ActionQueue<>();
        mReadDescriptorActionQueue = new ActionQueue<>();
        mWriteDescriptorActionQueue = new ActionQueue<>();
        mEnableNotificationActionQueue = new ActionQueue<>();
        mReadRemoteRssiActionQueue = new ActionQueue<>();
    }

    public ActionQueue<AbstractReadCharacteristicAction, UUID> getReadCharacteristicActionQueue() {
        return mReadCharacteristicActionQueue;
    }

    public ActionQueue<AbstractWriteCharacteristicAction, UUID> getWriteCharacteristicActionQueue() {
        return mWriteCharacteristicActionQueue;
    }

    public ActionQueue<AbstractReadDescriptorAction, UUID> getReadDescriptorActionQueue() {
        return mReadDescriptorActionQueue;
    }

    public ActionQueue<AbstractWriteDescriptorAction, UUID> getWriteDescriptorActionQueue() {
        return mWriteDescriptorActionQueue;
    }

    public ActionQueue<AbstractEnableNotificationAction, UUID> getEnableNotificationActionQueue() {
        return mEnableNotificationActionQueue;
    }

    public ActionQueue<AbstractReadRemoteRssiAction, Void> getReadRemoteRssiActionQueue() {
        return mReadRemoteRssiActionQueue;
    }

    public void enqueue(AbstractAction action) {
        if (action instanceof AbstractReadCharacteristicAction) {
            mReadCharacteristicActionQueue.enqueue((AbstractReadCharacteristicAction) action);
        } else if (action instanceof AbstractWriteCharacteristicAction) {
            mWriteCharacteristicActionQueue.enqueue((AbstractWriteCharacteristicAction) action);
        } else if (action instanceof AbstractReadDescriptorAction) {
            mReadDescriptorActionQueue.enqueue((AbstractReadDescriptorAction) action);
        } else if (action instanceof AbstractWriteDescriptorAction) {
            mWriteDescriptorActionQueue.enqueue((AbstractWriteDescriptorAction) action);
        } else if (action instanceof AbstractEnableNotificationAction) {
            mEnableNotificationActionQueue.enqueue((AbstractEnableNotificationAction) action);
        } else if (action instanceof AbstractReadRemoteRssiAction) {
            mReadRemoteRssiActionQueue.enqueue((AbstractReadRemoteRssiAction) action);
        } else {
            throw new IllegalArgumentException();
        }
    }
}

@@ -663,16 +663,45 @@
 ainer %7B%0A
+    private BleState mState;%0A
     priv
@@ -1275,24 +1275,64 @@
 ntainer() %7B%0A
+        mState = BleState.DISCONNECTED;%0A
         mRea
@@ -1680,32 +1680,169 @@
 eue%3C%3E();%0A    %7D%0A%0A
+    public BleState getState() %7B%0A        return mState;%0A    %7D%0A%0A    public void setState(BleState state) %7B%0A        mState = state;%0A    %7D%0A%0A
     public Actio

Implement StateContainer#{get,set}State()