#ifndef GITTREE_H
#define GITTREE_H

#include <nan.h>
#include <string>

extern "C" {
#include <git2.h>
}

#include "../include/tree.h"
#include "../include/repository.h"
#include "../include/tree_entry.h"
#include "../include/object.h"
#include "../include/treebuilder.h"
#include "../include/oid.h"


using namespace node;
using namespace v8;

class GitTree : public ObjectWrap {
  public:

    static Persistent<Function> constructor_template;
    static void Initialize (Handle<v8::Object> target);

        git_tree *GetValue();

    static Handle<Value> New(void *raw);
    
  private:
        GitTree(git_tree *raw);
    ~GitTree();
    
    static NAN_METHOD(New);

    
                  
    struct LookupBaton {
      int error_code;
      const git_error* error;
                    git_tree * out;
                            git_repository * repo;
                            const git_oid * id;
                  };
    class LookupWorker : public NanAsyncWorker {
      public:
        LookupWorker(
            LookupBaton *_baton,
            NanCallback *callback
        ) : NanAsyncWorker(callback)
          , baton(_baton) {};
        ~LookupWorker() {};
        void Execute();
        void HandleOKCallback();

      private:
        LookupBaton *baton;
    };
        
    static NAN_METHOD(Lookup);
                        
    static NAN_METHOD(Entrycount);
                        
    static NAN_METHOD(EntryByname);
                        
    static NAN_METHOD(EntryByindex);
                        
    struct EntryBypathBaton {
      int error_code;
      const git_error* error;
                    git_tree_entry * out;
                            const git_tree * root;
                            const char * path;
                  };
    class EntryBypathWorker : public NanAsyncWorker {
      public:
        EntryBypathWorker(
            EntryBypathBaton *_baton,
            NanCallback *callback
        ) : NanAsyncWorker(callback)
          , baton(_baton) {};
        ~EntryBypathWorker() {};
        void Execute();
        void HandleOKCallback();

      private:
        EntryBypathBaton *baton;
    };
        
    static NAN_METHOD(EntryBypath);
          
        git_tree *raw;
    };

#endif
