// This is a generated file, modify: generate/templates/templates/class_header.h

#ifndef GITBLAME_H
#define GITBLAME_H
#include <nan.h>
#include <string>
#include <utility>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <sstream>

#include "async_baton.h"
#include "async_worker.h"
#include "cleanup_handle.h"
#include "context.h"
#include "lock_master.h"
#include "nodegit_wrapper.h"
#include "promise_completion.h"
#include "reference_counter.h"
#include "worker_pool.h"

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

#include "../include/typedefs.h"

#include "../include/blame_hunk.h"
#include "../include/blame_line.h"
#include "../include/repository.h"
#include "../include/blame_options.h"
// Forward declaration.
struct git_blame {
};

using namespace node;
using namespace v8;

class GitBlame;
 
struct GitBlameTraits {
  typedef GitBlame cppClass;
  typedef git_blame cType;
 
  static const bool isDuplicable = false;
  static void duplicate(git_blame **dest, git_blame *src) {
     Nan::ThrowError("duplicate called on GitBlame which cannot be duplicated");
   }

  static std::string className() { return "GitBlame"; };
  static const bool isSingleton = false;
  static const bool isFreeable = true;
  static void free(git_blame *raw) {
    unsigned long referenceCount = 0;
     if (referenceCount == 0) {
      ::git_blame_free(raw); // :: to avoid calling this free recursively
    }
   }
};

class GitBlame : public
  NodeGitWrapper<GitBlameTraits>
{
    // grant full access to base class
    friend class NodeGitWrapper<GitBlameTraits>;
   public:
    GitBlame(const GitBlame &) = delete;
    GitBlame(GitBlame &&) = delete;
    GitBlame &operator=(const GitBlame &) = delete;
    GitBlame &operator=(GitBlame &&) = delete;

    static void InitializeComponent (v8::Local<v8::Object> target, nodegit::Context *nodegitContext);

                                          

  private:
    GitBlame()
      : NodeGitWrapper<GitBlameTraits>(
           "A new GitBlame cannot be instantiated."
       )
    {}
    GitBlame(git_blame *raw, bool selfFreeing, v8::Local<v8::Object> owner = v8::Local<v8::Object>())
      : NodeGitWrapper<GitBlameTraits>(raw, selfFreeing, owner)
    {}
    ~GitBlame();

    struct BufferBaton {
      int error_code;
      const git_error* error;
      git_blame * out;
      git_blame * base;
      const char * buffer;
      size_t buffer_len;
     };
    class BufferWorker : public nodegit::AsyncWorker {
      public:
        BufferWorker(
            BufferBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitBlame:Buffer", cleanupHandles)
          , baton(_baton) {};
        BufferWorker(const BufferWorker &) = delete;
        BufferWorker(BufferWorker &&) = delete;
        BufferWorker &operator=(const BufferWorker &) = delete;
        BufferWorker &operator=(BufferWorker &&) = delete;
        ~BufferWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        BufferBaton *baton;
    };

    static NAN_METHOD(Buffer);

    static NAN_METHOD(GetHunkByindex);

    static NAN_METHOD(GetHunkByline);

    static NAN_METHOD(GetHunkCount);

    static NAN_METHOD(HunkByindex);

    static NAN_METHOD(HunkByline);

    static NAN_METHOD(Hunkcount);

    static NAN_METHOD(LineByindex);

    static NAN_METHOD(Linecount);

    struct FileBaton {
      int error_code;
      const git_error* error;
      git_blame * out;
      git_repository * repo;
      const char * path;
      git_blame_options * options;
     };
    class FileWorker : public nodegit::AsyncWorker {
      public:
        FileWorker(
            FileBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitBlame:File", cleanupHandles)
          , baton(_baton) {};
        FileWorker(const FileWorker &) = delete;
        FileWorker(FileWorker &&) = delete;
        FileWorker &operator=(const FileWorker &) = delete;
        FileWorker &operator=(FileWorker &&) = delete;
        ~FileWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        FileBaton *baton;
    };

    static NAN_METHOD(File);
};

#endif
