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

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

#include "../include/treebuilder.h"
#include "../include/tree.h"
#include "../include/tree_entry.h"
#include "../include/oid.h"
#include "../include/repository.h"
// Forward declaration.
struct git_treebuilder {
};

using namespace node;
using namespace v8;

class GitTreebuilder : public ObjectWrap {
  public:

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

    git_treebuilder *GetValue();
    git_treebuilder **GetRefValue();

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

  private:
    GitTreebuilder(git_treebuilder *raw, bool selfFreeing);
    ~GitTreebuilder();

    static NAN_METHOD(JSNewFunction);


    static NAN_METHOD(Clear);

    struct CreateBaton {
      int error_code;
      const git_error* error;
      git_treebuilder * out;
      const git_tree * source;
    };
    class CreateWorker : public NanAsyncWorker {
      public:
        CreateWorker(
            CreateBaton *_baton,
            NanCallback *callback
        ) : NanAsyncWorker(callback)
          , baton(_baton) {};
        ~CreateWorker() {};
        void Execute();
        void HandleOKCallback();

      private:
        CreateBaton *baton;
    };

    static NAN_METHOD(Create);

    static NAN_METHOD(Entrycount);

    static NAN_METHOD(Get);

    struct InsertBaton {
      int error_code;
      const git_error* error;
      const git_tree_entry * out;
      git_treebuilder * bld;
      const char * filename;
      const git_oid * id;
      bool idNeedsFree;
      git_filemode_t filemode;
    };
    class InsertWorker : public NanAsyncWorker {
      public:
        InsertWorker(
            InsertBaton *_baton,
            NanCallback *callback
        ) : NanAsyncWorker(callback)
          , baton(_baton) {};
        ~InsertWorker() {};
        void Execute();
        void HandleOKCallback();

      private:
        InsertBaton *baton;
    };

    static NAN_METHOD(Insert);

    static NAN_METHOD(Remove);

    static NAN_METHOD(Write);
    git_treebuilder *raw;
};

#endif
