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

#ifndef GITREPOSITORY_H
#define GITREPOSITORY_H
#include <nan.h>
#include <string>
#include <queue>
#include <utility>
#include <unordered_map>
#include <sstream>

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

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

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

#include "git2/sys/repository.h"
#include "../include/submodule.h"
#include "../include/remote.h"
#include "../include/config.h"
#include "../include/buf.h"
#include "../include/oid.h"
#include "../include/reference.h"
#include "../include/index.h"
#include "../include/repository_init_options.h"
#include "../include/odb.h"
#include "../include/worktree.h"
#include "../include/refdb.h"
#include "../include/annotated_commit.h"
// Forward declaration.
struct git_repository {
};

using namespace node;
using namespace v8;

class GitRepository;

struct GitRepositoryTraits {
  typedef GitRepository cppClass;
  typedef git_repository cType;

  static const bool isDuplicable = false;
  static void duplicate(git_repository **dest, git_repository *src) {
     Nan::ThrowError("duplicate called on GitRepository which cannot be duplicated");
   }

  static std::string className() { return "GitRepository"; };
  static const bool isSingleton = true;
  static const bool isFreeable = true;
  static void free(git_repository *raw) {
    unsigned long referenceCount = 0;
    referenceCount = ReferenceCounter::decrementCountForPointer((void *)raw);
     if (referenceCount == 0) {
      ::git_repository_free(raw); // :: to avoid calling this free recursively
    }
   }
};

class GitRepository : public
  NodeGitWrapper<GitRepositoryTraits>
{
    // grant full access to base class
    friend class NodeGitWrapper<GitRepositoryTraits>;
   public:
    static void InitializeComponent (v8::Local<v8::Object> target, nodegit::Context *nodegitContext);

                     static int FetchheadForeach_callback_cppCallback (
      const char * refname
      ,
       const char * remote_url
      ,
       const git_oid * oid
      ,
       unsigned int is_merge
      ,
       void * payload
      );

    static void FetchheadForeach_callback_cancelAsync(void *baton);
    static void FetchheadForeach_callback_async(void *baton);
    static void FetchheadForeach_callback_promiseCompleted(bool isFulfilled, nodegit::AsyncBaton *_baton, v8::Local<v8::Value> result);
    class FetchheadForeach_CallbackBaton : public nodegit::AsyncBatonWithResult<int> {
    public:
      const char * refname;
      const char * remote_url;
      const git_oid * oid;
      unsigned int is_merge;
      void * payload;
 
      FetchheadForeach_CallbackBaton(const int &defaultResult)
        : nodegit::AsyncBatonWithResult<int>(defaultResult) {
        }
    };
                                                                   static int MergeheadForeach_callback_cppCallback (
      const git_oid * oid
      ,
       void * payload
      );

    static void MergeheadForeach_callback_cancelAsync(void *baton);
    static void MergeheadForeach_callback_async(void *baton);
    static void MergeheadForeach_callback_promiseCompleted(bool isFulfilled, nodegit::AsyncBaton *_baton, v8::Local<v8::Value> result);
    class MergeheadForeach_CallbackBaton : public nodegit::AsyncBatonWithResult<int> {
    public:
      const git_oid * oid;
      void * payload;
 
      MergeheadForeach_CallbackBaton(const int &defaultResult)
        : nodegit::AsyncBatonWithResult<int>(defaultResult) {
        }
    };
                                                                                                         

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

    static NAN_METHOD(Commondir);

    struct ConfigBaton {
      int error_code;
      const git_error* error;
      git_config * out;
      git_repository * repo;
    };
    class ConfigWorker : public nodegit::AsyncWorker {
      public:
        ConfigWorker(
            ConfigBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:Config")
          , baton(_baton) {};
        ~ConfigWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        ConfigBaton *baton;
    };

    static NAN_METHOD(Config);

    static NAN_METHOD(DetachHead);

    struct DiscoverBaton {
      int error_code;
      const git_error* error;
      git_buf * out;
      const char * start_path;
      int across_fs;
      const char * ceiling_dirs;
    };
    class DiscoverWorker : public nodegit::AsyncWorker {
      public:
        DiscoverWorker(
            DiscoverBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:Discover")
          , baton(_baton) {};
        ~DiscoverWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        DiscoverBaton *baton;
    };

    static NAN_METHOD(Discover);

    struct FetchheadForeachBaton {
      int error_code;
      const git_error* error;
      git_repository * repo;
      git_repository_fetchhead_foreach_cb callback;
      void * payload;
    };
    class FetchheadForeachWorker : public nodegit::AsyncWorker {
      public:
        FetchheadForeachWorker(
            FetchheadForeachBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:FetchheadForeach")
          , baton(_baton) {};
        ~FetchheadForeachWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        FetchheadForeachBaton *baton;
    };

    static NAN_METHOD(FetchheadForeach);

    static NAN_METHOD(GetNamespace);

    struct HeadBaton {
      int error_code;
      const git_error* error;
      git_reference * out;
      git_repository * repo;
    };
    class HeadWorker : public nodegit::AsyncWorker {
      public:
        HeadWorker(
            HeadBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:Head")
          , baton(_baton) {};
        ~HeadWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        HeadBaton *baton;
    };

    static NAN_METHOD(Head);

    static NAN_METHOD(HeadDetached);

    static NAN_METHOD(HeadDetachedForWorktree);

    struct HeadForWorktreeBaton {
      int error_code;
      const git_error* error;
      git_reference * out;
      git_repository * repo;
      const char * name;
    };
    class HeadForWorktreeWorker : public nodegit::AsyncWorker {
      public:
        HeadForWorktreeWorker(
            HeadForWorktreeBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:HeadForWorktree")
          , baton(_baton) {};
        ~HeadForWorktreeWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        HeadForWorktreeBaton *baton;
    };

    static NAN_METHOD(HeadForWorktree);

    static NAN_METHOD(HeadUnborn);

    static NAN_METHOD(Ident);

    struct IndexBaton {
      int error_code;
      const git_error* error;
      git_index * out;
      git_repository * repo;
    };
    class IndexWorker : public nodegit::AsyncWorker {
      public:
        IndexWorker(
            IndexBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:Index")
          , baton(_baton) {};
        ~IndexWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        IndexBaton *baton;
    };

    static NAN_METHOD(Index);

    struct InitBaton {
      int error_code;
      const git_error* error;
      git_repository * out;
      const char * path;
      unsigned int is_bare;
    };
    class InitWorker : public nodegit::AsyncWorker {
      public:
        InitWorker(
            InitBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:Init")
          , baton(_baton) {};
        ~InitWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        InitBaton *baton;
    };

    static NAN_METHOD(Init);

    struct InitExtBaton {
      int error_code;
      const git_error* error;
      git_repository * out;
      const char * repo_path;
      git_repository_init_options * opts;
    };
    class InitExtWorker : public nodegit::AsyncWorker {
      public:
        InitExtWorker(
            InitExtBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:InitExt")
          , baton(_baton) {};
        ~InitExtWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        InitExtBaton *baton;
    };

    static NAN_METHOD(InitExt);

    static NAN_METHOD(IsBare);

    static NAN_METHOD(IsEmpty);

    static NAN_METHOD(IsShallow);

    static NAN_METHOD(IsWorktree);

    struct ItemPathBaton {
      int error_code;
      const git_error* error;
      git_buf * out;
      const git_repository * repo;
      git_repository_item_t item;
    };
    class ItemPathWorker : public nodegit::AsyncWorker {
      public:
        ItemPathWorker(
            ItemPathBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:ItemPath")
          , baton(_baton) {};
        ~ItemPathWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        ItemPathBaton *baton;
    };

    static NAN_METHOD(ItemPath);

    struct MergeheadForeachBaton {
      int error_code;
      const git_error* error;
      git_repository * repo;
      git_repository_mergehead_foreach_cb callback;
      void * payload;
    };
    class MergeheadForeachWorker : public nodegit::AsyncWorker {
      public:
        MergeheadForeachWorker(
            MergeheadForeachBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:MergeheadForeach")
          , baton(_baton) {};
        ~MergeheadForeachWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        MergeheadForeachBaton *baton;
    };

    static NAN_METHOD(MergeheadForeach);

    static NAN_METHOD(MessageRemove);

    struct OdbBaton {
      int error_code;
      const git_error* error;
      git_odb * out;
      git_repository * repo;
    };
    class OdbWorker : public nodegit::AsyncWorker {
      public:
        OdbWorker(
            OdbBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:Odb")
          , baton(_baton) {};
        ~OdbWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        OdbBaton *baton;
    };

    static NAN_METHOD(Odb);

    struct OpenBaton {
      int error_code;
      const git_error* error;
      git_repository * out;
      const char * path;
    };
    class OpenWorker : public nodegit::AsyncWorker {
      public:
        OpenWorker(
            OpenBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:Open")
          , baton(_baton) {};
        ~OpenWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        OpenBaton *baton;
    };

    static NAN_METHOD(Open);

    struct OpenBareBaton {
      int error_code;
      const git_error* error;
      git_repository * out;
      const char * bare_path;
    };
    class OpenBareWorker : public nodegit::AsyncWorker {
      public:
        OpenBareWorker(
            OpenBareBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:OpenBare")
          , baton(_baton) {};
        ~OpenBareWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        OpenBareBaton *baton;
    };

    static NAN_METHOD(OpenBare);

    struct OpenExtBaton {
      int error_code;
      const git_error* error;
      git_repository * out;
      const char * path;
      unsigned int flags;
      const char * ceiling_dirs;
    };
    class OpenExtWorker : public nodegit::AsyncWorker {
      public:
        OpenExtWorker(
            OpenExtBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:OpenExt")
          , baton(_baton) {};
        ~OpenExtWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        OpenExtBaton *baton;
    };

    static NAN_METHOD(OpenExt);

    struct OpenFromWorktreeBaton {
      int error_code;
      const git_error* error;
      git_repository * out;
      git_worktree * wt;
    };
    class OpenFromWorktreeWorker : public nodegit::AsyncWorker {
      public:
        OpenFromWorktreeWorker(
            OpenFromWorktreeBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:OpenFromWorktree")
          , baton(_baton) {};
        ~OpenFromWorktreeWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        OpenFromWorktreeBaton *baton;
    };

    static NAN_METHOD(OpenFromWorktree);

    static NAN_METHOD(Path);

    struct RefdbBaton {
      int error_code;
      const git_error* error;
      git_refdb * out;
      git_repository * repo;
    };
    class RefdbWorker : public nodegit::AsyncWorker {
      public:
        RefdbWorker(
            RefdbBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:Refdb")
          , baton(_baton) {};
        ~RefdbWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        RefdbBaton *baton;
    };

    static NAN_METHOD(Refdb);

    struct SetHeadBaton {
      int error_code;
      const git_error* error;
      git_repository * repo;
      const char * refname;
    };
    class SetHeadWorker : public nodegit::AsyncWorker {
      public:
        SetHeadWorker(
            SetHeadBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:SetHead")
          , baton(_baton) {};
        ~SetHeadWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        SetHeadBaton *baton;
    };

    static NAN_METHOD(SetHead);

    static NAN_METHOD(SetHeadDetached);

    static NAN_METHOD(SetHeadDetachedFromAnnotated);

    static NAN_METHOD(SetIdent);

    static NAN_METHOD(SetNamespace);

    static NAN_METHOD(SetWorkdir);

    static NAN_METHOD(State);

    static NAN_METHOD(StateCleanup);

    static NAN_METHOD(Workdir);

    struct WrapOdbBaton {
      int error_code;
      const git_error* error;
      git_repository * out;
      git_odb * odb;
    };
    class WrapOdbWorker : public nodegit::AsyncWorker {
      public:
        WrapOdbWorker(
            WrapOdbBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:WrapOdb")
          , baton(_baton) {};
        ~WrapOdbWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        WrapOdbBaton *baton;
    };

    static NAN_METHOD(WrapOdb);

    struct CleanupBaton {
      int error_code;
      const git_error* error;
      git_repository * repo;
    };
    class CleanupWorker : public nodegit::AsyncWorker {
      public:
        CleanupWorker(
            CleanupBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:Cleanup")
          , baton(_baton) {};
        ~CleanupWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        CleanupBaton *baton;
    };

    static NAN_METHOD(Cleanup);

    struct GetReferencesBaton {
      int error_code;
      const git_error* error;
      std::vector<git_reference *> * out;
      git_repository * repo;
    };
    class GetReferencesWorker : public nodegit::AsyncWorker {
      public:
        GetReferencesWorker(
            GetReferencesBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:GetReferences")
          , baton(_baton) {};
        ~GetReferencesWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        GetReferencesBaton *baton;
    };

    static NAN_METHOD(GetReferences);

    struct GetSubmodulesBaton {
      int error_code;
      const git_error* error;
      std::vector<git_submodule *> * out;
      git_repository * repo;
    };
    class GetSubmodulesWorker : public nodegit::AsyncWorker {
      public:
        GetSubmodulesWorker(
            GetSubmodulesBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:GetSubmodules")
          , baton(_baton) {};
        ~GetSubmodulesWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        GetSubmodulesBaton *baton;
    };

    static NAN_METHOD(GetSubmodules);

    struct GetRemotesBaton {
      int error_code;
      const git_error* error;
      std::vector<git_remote *> * out;
      git_repository * repo;
    };
    class GetRemotesWorker : public nodegit::AsyncWorker {
      public:
        GetRemotesWorker(
            GetRemotesBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:GetRemotes")
          , baton(_baton) {};
        ~GetRemotesWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        GetRemotesBaton *baton;
    };

    static NAN_METHOD(GetRemotes);

    struct RefreshReferencesBaton {
      int error_code;
      const git_error* error;
      void * out;
      git_repository * repo;
    };
    class RefreshReferencesWorker : public nodegit::AsyncWorker {
      public:
        RefreshReferencesWorker(
            RefreshReferencesBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRepository:RefreshReferences")
          , baton(_baton) {};
        ~RefreshReferencesWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        RefreshReferencesBaton *baton;
    };

    static NAN_METHOD(RefreshReferences);

    static NAN_METHOD(SetIndex);

    static NAN_METHOD(SubmoduleCacheAll);

    static NAN_METHOD(SubmoduleCacheClear);

    struct FetchheadForeach_globalPayload {
      Nan::Callback * callback;

      FetchheadForeach_globalPayload() {
        callback = NULL;
      }

      ~FetchheadForeach_globalPayload() {
        if (callback != NULL) {
          delete callback;
        }
      }
    };

    struct MergeheadForeach_globalPayload {
      Nan::Callback * callback;

      MergeheadForeach_globalPayload() {
        callback = NULL;
      }

      ~MergeheadForeach_globalPayload() {
        if (callback != NULL) {
          delete callback;
        }
      }
    };
};

#endif
