#ifndef TABLE_H
#define TABLE_H

#include <nan.h>
#include "transaction.h"

using namespace v8;

class Table : public Nan::ObjectWrap {
public:
   Table(Transaction *transaction, libagent_Table *ref);

   static NAN_MODULE_INIT(Init);
   static bool IsTable(Local<Value> obj);

   static Table *CreateMap(Transaction *transaction, size_t size);
   static Table *CreateArray(Transaction *transaction, size_t size);
   static Table *FromObject(Transaction *transaction, Local<Object> obj);

   Local<Value> ToValue();
   void Set(const char *key, Local<Value> val);
   void Set(int index, Local<Value> val);

private:
   ~Table();

   static NAN_GETTER(Length);
   static NAN_PROPERTY_GETTER(GetProperty);
   static NAN_PROPERTY_SETTER(SetProperty);
   static NAN_INDEX_GETTER(GetIndex);
   static NAN_INDEX_SETTER(SetIndex);
   static NAN_METHOD(ToString);

   static Nan::Persistent<FunctionTemplate> constructor;
   Transaction *transaction;
   libagent_Table *ref;
   Libagent *libagent;

   friend class Transaction;
};
#endif
