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

#ifndef GITREBASE_H
#define GITREBASE_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 "../include/oid.h"
#include "../include/signature.h"
#include "../include/repository.h"
#include "../include/annotated_commit.h"
#include "../include/rebase_options.h"
#include "../include/index.h"
#include "../include/rebase_operation.h"
// Forward declaration.
struct git_rebase {
};

using namespace node;
using namespace v8;

class GitRebase;

struct GitRebaseTraits {
  typedef GitRebase cppClass;
  typedef git_rebase cType;

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

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

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

                                                           

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

    struct AbortBaton {
      int error_code;
      const git_error* error;
      git_rebase * rebase;
    };
    class AbortWorker : public nodegit::AsyncWorker {
      public:
        AbortWorker(
            AbortBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRebase:Abort")
          , baton(_baton) {};
        ~AbortWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        AbortBaton *baton;
    };

    static NAN_METHOD(Abort);

    struct CommitBaton {
      int error_code;
      const git_error* error;
      git_oid * id;
      git_rebase * rebase;
      const git_signature * author;
      const git_signature * committer;
      const char * message_encoding;
      const char * message;
    };
    class CommitWorker : public nodegit::AsyncWorker {
      public:
        CommitWorker(
            CommitBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRebase:Commit")
          , baton(_baton) {};
        ~CommitWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        CommitBaton *baton;
    };

    static NAN_METHOD(Commit);

    static NAN_METHOD(Finish);

    struct InitBaton {
      int error_code;
      const git_error* error;
      git_rebase * out;
      git_repository * repo;
      const git_annotated_commit * branch;
      const git_annotated_commit * upstream;
      const git_annotated_commit * onto;
      const git_rebase_options * opts;
    };
    class InitWorker : public nodegit::AsyncWorker {
      public:
        InitWorker(
            InitBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRebase:Init")
          , baton(_baton) {};
        ~InitWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        InitBaton *baton;
    };

    static NAN_METHOD(Init);

    static NAN_METHOD(InmemoryIndex);

    struct NextBaton {
      int error_code;
      const git_error* error;
      git_rebase_operation * operation;
      git_rebase * rebase;
    };
    class NextWorker : public nodegit::AsyncWorker {
      public:
        NextWorker(
            NextBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitRebase:Next")
          , baton(_baton) {};
        ~NextWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        NextBaton *baton;
    };

    static NAN_METHOD(Next);

    static NAN_METHOD(OntoId);

    static NAN_METHOD(OntoName);

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

      private:
        OpenBaton *baton;
    };

    static NAN_METHOD(Open);

    static NAN_METHOD(OperationByindex);

    static NAN_METHOD(OperationCurrent);

    static NAN_METHOD(OperationEntrycount);

    static NAN_METHOD(OrigHeadId);

    static NAN_METHOD(OrigHeadName);
};

#endif
