"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.raftPubSubscriptionHelper = exports.raftDisconnectedSubscriptionHelper = void 0;
const raftPubSubscriptionHelper = raft => {
  let observer = null;
  return {
    subscribe: callback => {
      observer = raftPubSubscriptionObserver_(callback);
      raft.subscribe(observer, ["raftinfo"]);
    },
    unsubscribe: () => {
      if (observer) {
        raft.unsubscribe(observer);
      }
    }
  };
};
exports.raftPubSubscriptionHelper = raftPubSubscriptionHelper;
const raftPubSubscriptionObserver_ = callback => {
  return {
    notify(eventType, eventEnum, eventName, eventData) {
      switch (eventType) {
        case "raftinfo":
          switch (eventEnum) {
            case "STATE_INFO":
              callback(eventData);
              break;
            default:
              break;
          }
          break;
      }
    }
  };
};

/** 
 * RAFT Disconnected Subscription Helper
 */
const raftDisconnectedSubscriptionHelper = raft => {
  let observer = null;
  return {
    subscribe: callback => {
      observer = raftDisconnectedSubscriptionObserver_(callback);
      raft.subscribe(observer, ["conn"]);
    },
    unsubscribe: () => {
      if (observer) {
        raft.unsubscribe(observer);
      }
    }
  };
};
exports.raftDisconnectedSubscriptionHelper = raftDisconnectedSubscriptionHelper;
const raftDisconnectedSubscriptionObserver_ = callback => {
  return {
    notify(eventType, eventEnum, eventName, eventData) {
      switch (eventType) {
        case "conn":
          switch (eventEnum) {
            case 3:
              callback();
              break;
            default:
              break;
          }
          break;
      }
    }
  };
};