var Store = function () {
  this._store = null;
  this._fetch = null;
  this._list = null;

  this.store = function (event) {
    var id = this.eventCount(),
        fetchedEvent = null,
        ret = {};

    this._store(event);

    fetchedEvent = this.fetch(id);

    ret = {
      id: id,
      success: event == fetchedEvent
    };

    if (ret.success)
      ret.event = fetchedEvent;
    else
      ret.error = {message: "No such Event: " + id}

    return ret;

    return {
      id: id,
      success: event == fetchedEvent,
      event: fetchedEvent
    };
  }

  this.fetch = function (id) {
    return this._fetch(id);
  }

  this.list = function (limit, offset) {
    if (!offset)
      offset = 0;

    if (!limit)
      limit = 1000;

    limit = Math.min(limit, (iws.events.eventCount() - offset));

    return this._list(limit, offset);
  }

  this.eventCount = function (offset) {
    if (!offset)
      offset = 0;

    return this._eventCount(offset);
  }

  this.config = function (callback) {
    callback.bind(this).call();

    return this;
  };

  this.onStore = function (callback) {
    this._store = callback.bind(this);

    return this;
  };

  this.onFetch = function (callback) {
    this._fetch = callback.bind(this);

    return this;
  };

  this.onList = function (callback) {
    this._list = callback.bind(this);

    return this;
  };

  this.onEventCount = function (callback) {
    this._eventCount = callback.bind(this);

    return this;
  }

  return this;
}

module.exports = Store;
