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

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

#include "../include/patch.h"
#include "../include/blob.h"
#include "../include/diff_options.h"
#include "../include/diff.h"
#include "../include/diff_delta.h"
#include "../include/diff_hunk.h"
#include "../include/diff_line.h"
// Forward declaration.
struct git_patch {
};

using namespace node;
using namespace v8;

class GitPatch : public ObjectWrap {
public:

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

  git_patch *GetValue();
  git_patch **GetRefValue();

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

private:
  GitPatch(git_patch *raw, bool selfFreeing);
  ~GitPatch();

  static NAN_METHOD(JSNewFunction);


  struct FromBlobAndBufferBaton {
    int error_code;
    const git_error* error;
    git_patch * out;
    const git_blob * old_blob;
    const char * old_as_path;
    const char * buffer;
    size_t buffer_len;
    const char * buffer_as_path;
    const git_diff_options * opts;
  };
  class FromBlobAndBufferWorker : public NanAsyncWorker {
  public:
    FromBlobAndBufferWorker(
      FromBlobAndBufferBaton *_baton,
      NanCallback *callback
    ) : NanAsyncWorker(callback)
      , baton(_baton) {};
    ~FromBlobAndBufferWorker() {};
    void Execute();
    void HandleOKCallback();

  private:
    FromBlobAndBufferBaton *baton;
  };

  static NAN_METHOD(FromBlobAndBuffer);

  struct FromBlobsBaton {
    int error_code;
    const git_error* error;
    git_patch * out;
    const git_blob * old_blob;
    const char * old_as_path;
    const git_blob * new_blob;
    const char * new_as_path;
    const git_diff_options * opts;
  };
  class FromBlobsWorker : public NanAsyncWorker {
  public:
    FromBlobsWorker(
      FromBlobsBaton *_baton,
      NanCallback *callback
    ) : NanAsyncWorker(callback)
      , baton(_baton) {};
    ~FromBlobsWorker() {};
    void Execute();
    void HandleOKCallback();

  private:
    FromBlobsBaton *baton;
  };

  static NAN_METHOD(FromBlobs);

  static NAN_METHOD(FromDiff);

  static NAN_METHOD(GetDelta);

  static NAN_METHOD(GetHunk);

  static NAN_METHOD(GetLineInHunk);

  static NAN_METHOD(NumHunks);

  static NAN_METHOD(NumLinesInHunk);

  static NAN_METHOD(Size);
  git_patch *raw;
};

#endif
