#ifndef GITINDEX_H
#define GITINDEX_H
// generated from class_header.h
#include <nan.h>
#include <string>

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

#include "../include/index.h"
#include "../include/index_entry.h"
#include "../include/repository.h"
#include "../include/tree.h"
#include "../include/oid.h"
// Forward declaration.
struct git_index {
};

using namespace node;
using namespace v8;

class GitIndex : public ObjectWrap {
  public:

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

    git_index *GetValue();
    git_index **GetRefValue();

    static Handle<Value> New(void *raw, bool selfFreeing);
    bool selfFreeing;

  private:
    GitIndex(git_index *raw, bool selfFreeing);
    ~GitIndex();

    static NAN_METHOD(JSNewFunction);


    static NAN_METHOD(Add);

    static NAN_METHOD(AddBypath);

    static NAN_METHOD(Caps);

    static NAN_METHOD(Clear);

    static NAN_METHOD(ConflictAdd);

    static NAN_METHOD(ConflictCleanup);

    static NAN_METHOD(ConflictRemove);

    static NAN_METHOD(EntryStage);

    static NAN_METHOD(Entrycount);

    static NAN_METHOD(GetByindex);

    static NAN_METHOD(GetBypath);

    static NAN_METHOD(HasConflicts);

    struct OpenBaton {
      int error_code;
      const git_error* error;
      git_index * out;
      const char * index_path;
    };
    class OpenWorker : public NanAsyncWorker {
      public:
        OpenWorker(
            OpenBaton *_baton,
            NanCallback *callback
        ) : NanAsyncWorker(callback)
          , baton(_baton) {};
        ~OpenWorker() {};
        void Execute();
        void HandleOKCallback();

      private:
        OpenBaton *baton;
    };

    static NAN_METHOD(Open);

    static NAN_METHOD(Owner);

    static NAN_METHOD(Path);

    static NAN_METHOD(Read);

    static NAN_METHOD(ReadTree);

    static NAN_METHOD(Remove);

    static NAN_METHOD(RemoveBypath);

    static NAN_METHOD(RemoveDirectory);

    static NAN_METHOD(SetCaps);

    static NAN_METHOD(Write);

    struct WriteTreeBaton {
      int error_code;
      const git_error* error;
      git_oid * out;
      git_index * index;
    };
    class WriteTreeWorker : public NanAsyncWorker {
      public:
        WriteTreeWorker(
            WriteTreeBaton *_baton,
            NanCallback *callback
        ) : NanAsyncWorker(callback)
          , baton(_baton) {};
        ~WriteTreeWorker() {};
        void Execute();
        void HandleOKCallback();

      private:
        WriteTreeBaton *baton;
    };

    static NAN_METHOD(WriteTree);

    struct WriteTreeToBaton {
      int error_code;
      const git_error* error;
      git_oid * out;
      git_index * index;
      git_repository * repo;
    };
    class WriteTreeToWorker : public NanAsyncWorker {
      public:
        WriteTreeToWorker(
            WriteTreeToBaton *_baton,
            NanCallback *callback
        ) : NanAsyncWorker(callback)
          , baton(_baton) {};
        ~WriteTreeToWorker() {};
        void Execute();
        void HandleOKCallback();

      private:
        WriteTreeToBaton *baton;
    };

    static NAN_METHOD(WriteTreeTo);
    git_index *raw;
};

#endif
