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

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

#include "../include/merge_head.h"
#include "../include/repository.h"
#include "../include/oid.h"
#include "../include/reference.h"
// Forward declaration.
struct git_merge_head {
};

using namespace node;
using namespace v8;

class GitMergeHead : public ObjectWrap {
public:

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

  git_merge_head *GetValue();
  git_merge_head **GetRefValue();

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

private:
  GitMergeHead(git_merge_head *raw, bool selfFreeing);
  ~GitMergeHead();

  static NAN_METHOD(JSNewFunction);


  struct FromFetchheadBaton {
    int error_code;
    const git_error* error;
    git_merge_head * out;
    git_repository * repo;
    const char * branch_name;
    const char * remote_url;
    const git_oid * oid;
    bool oidNeedsFree;
  };
  class FromFetchheadWorker : public NanAsyncWorker {
  public:
    FromFetchheadWorker(
      FromFetchheadBaton *_baton,
      NanCallback *callback
    ) : NanAsyncWorker(callback)
      , baton(_baton) {};
    ~FromFetchheadWorker() {};
    void Execute();
    void HandleOKCallback();

  private:
    FromFetchheadBaton *baton;
  };

  static NAN_METHOD(FromFetchhead);

  struct FromIdBaton {
    int error_code;
    const git_error* error;
    git_merge_head * out;
    git_repository * repo;
    const git_oid * id;
    bool idNeedsFree;
  };
  class FromIdWorker : public NanAsyncWorker {
  public:
    FromIdWorker(
      FromIdBaton *_baton,
      NanCallback *callback
    ) : NanAsyncWorker(callback)
      , baton(_baton) {};
    ~FromIdWorker() {};
    void Execute();
    void HandleOKCallback();

  private:
    FromIdBaton *baton;
  };

  static NAN_METHOD(FromId);

  struct FromRefBaton {
    int error_code;
    const git_error* error;
    git_merge_head * out;
    git_repository * repo;
    const git_reference * ref;
  };
  class FromRefWorker : public NanAsyncWorker {
  public:
    FromRefWorker(
      FromRefBaton *_baton,
      NanCallback *callback
    ) : NanAsyncWorker(callback)
      , baton(_baton) {};
    ~FromRefWorker() {};
    void Execute();
    void HandleOKCallback();

  private:
    FromRefBaton *baton;
  };

  static NAN_METHOD(FromRef);

  static NAN_METHOD(Id);
  git_merge_head *raw;
};

#endif
