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

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

#include "../include/buf.h"

using namespace node;
using namespace v8;

class GitBuf : public ObjectWrap {
  public:

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

    git_buf *GetValue();
    git_buf **GetRefValue();

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

  private:
    GitBuf(git_buf *raw, bool selfFreeing);
    ~GitBuf();

    static NAN_METHOD(JSNewFunction);

    static NAN_METHOD(Ptr);
    static NAN_METHOD(Asize);
    static NAN_METHOD(Size);

    struct GrowBaton {
      int error_code;
      const git_error* error;
      git_buf * buffer;
      size_t target_size;
    };
    class GrowWorker : public NanAsyncWorker {
      public:
        GrowWorker(
            GrowBaton *_baton,
            NanCallback *callback
        ) : NanAsyncWorker(callback)
          , baton(_baton) {};
        ~GrowWorker() {};
        void Execute();
        void HandleOKCallback();

      private:
        GrowBaton *baton;
    };

    static NAN_METHOD(Grow);

    struct SetBaton {
      int error_code;
      const git_error* error;
      git_buf * buffer;
      const void * data;
      size_t datalen;
    };
    class SetWorker : public NanAsyncWorker {
      public:
        SetWorker(
            SetBaton *_baton,
            NanCallback *callback
        ) : NanAsyncWorker(callback)
          , baton(_baton) {};
        ~SetWorker() {};
        void Execute();
        void HandleOKCallback();

      private:
        SetBaton *baton;
    };

    static NAN_METHOD(Set);
    git_buf *raw;
};

#endif
