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

#ifndef GITGRAPH_H
#define GITGRAPH_H
#include <nan.h>
#include <string>
#include <utility>
#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"

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

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

#include "../include/repository.h"
#include "../include/oid.h"

using namespace node;
using namespace v8;


class GitGraph : public
  Nan::ObjectWrap
{
   public:
    GitGraph(const GitGraph &) = delete;
    GitGraph(GitGraph &&) = delete;
    GitGraph &operator=(const GitGraph &) = delete;
    GitGraph &operator=(GitGraph &&) = delete;

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

             

  private:

    struct AheadBehindBaton {
      int error_code;
      const git_error* error;
      size_t * ahead;
      size_t * behind;
      git_repository * repo;
      const git_oid * local;
      bool localNeedsFree;
      const git_oid * upstream;
      bool upstreamNeedsFree;
     };
    class AheadBehindWorker : public nodegit::AsyncWorker {
      public:
        AheadBehindWorker(
            AheadBehindBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitGraph:AheadBehind", cleanupHandles)
          , baton(_baton) {};
        AheadBehindWorker(const AheadBehindWorker &) = delete;
        AheadBehindWorker(AheadBehindWorker &&) = delete;
        AheadBehindWorker &operator=(const AheadBehindWorker &) = delete;
        AheadBehindWorker &operator=(AheadBehindWorker &&) = delete;
        ~AheadBehindWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        AheadBehindBaton *baton;
    };

    static NAN_METHOD(AheadBehind);

    struct DescendantOfBaton {
      int error_code;
      const git_error* error;
      git_repository * repo;
      const git_oid * commit;
      bool commitNeedsFree;
      const git_oid * ancestor;
      bool ancestorNeedsFree;
     };
    class DescendantOfWorker : public nodegit::AsyncWorker {
      public:
        DescendantOfWorker(
            DescendantOfBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitGraph:DescendantOf", cleanupHandles)
          , baton(_baton) {};
        DescendantOfWorker(const DescendantOfWorker &) = delete;
        DescendantOfWorker(DescendantOfWorker &&) = delete;
        DescendantOfWorker &operator=(const DescendantOfWorker &) = delete;
        DescendantOfWorker &operator=(DescendantOfWorker &&) = delete;
        ~DescendantOfWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        DescendantOfBaton *baton;
    };

    static NAN_METHOD(DescendantOf);
};

#endif
