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

#ifndef GITREFLOG_H
#define GITREFLOG_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/oid.h"
#include "../include/signature.h"
#include "../include/repository.h"
#include "../include/reflog_entry.h"
// Forward declaration.
struct git_reflog {
};

using namespace node;
using namespace v8;

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

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

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

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

                                    

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

    static NAN_METHOD(Append);

    static NAN_METHOD(Delete);

    static NAN_METHOD(Drop);

    static NAN_METHOD(EntryByindex);

    static NAN_METHOD(Entrycount);

    struct ReadBaton {
      int error_code;
      const git_error* error;
      git_reflog * out;
      git_repository * repo;
      const char * name;
     };
    class ReadWorker : public nodegit::AsyncWorker {
      public:
        ReadWorker(
            ReadBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitReflog:Read", cleanupHandles)
          , baton(_baton) {};
        ReadWorker(const ReadWorker &) = delete;
        ReadWorker(ReadWorker &&) = delete;
        ReadWorker &operator=(const ReadWorker &) = delete;
        ReadWorker &operator=(ReadWorker &&) = delete;
        ~ReadWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        ReadBaton *baton;
    };

    static NAN_METHOD(Read);

    static NAN_METHOD(Rename);

    struct WriteBaton {
      int error_code;
      const git_error* error;
      git_reflog * reflog;
     };
    class WriteWorker : public nodegit::AsyncWorker {
      public:
        WriteWorker(
            WriteBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitReflog:Write", cleanupHandles)
          , baton(_baton) {};
        WriteWorker(const WriteWorker &) = delete;
        WriteWorker(WriteWorker &&) = delete;
        WriteWorker &operator=(const WriteWorker &) = delete;
        WriteWorker &operator=(WriteWorker &&) = delete;
        ~WriteWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        WriteBaton *baton;
    };

    static NAN_METHOD(Write);
};

#endif
