const BaseState = require('@abtnode/core/lib/states/base');
const MessageState = require('./message');

const states = {};

// eslint-disable-next-line no-unused-vars
const init = (dataDir, options = {}) => {
  const messageState = new MessageState(dataDir);

  Object.assign(states, {
    message: messageState,
  });
};

module.exports = new Proxy(
  {},
  {
    get(target, prop) {
      if (prop === 'init') {
        return init;
      }

      if (states[prop] instanceof BaseState) {
        return states[prop];
      }

      throw new Error(`State ${String(prop)} may not be initialized`);
    },
  }
);
