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

#ifndef GITCHERRYPICK_H
#define GITCHERRYPICK_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/repository.h"
#include "../include/commit.h"
#include "../include/cherrypick_options.h"
#include "../include/index.h"
#include "../include/merge_options.h"

using namespace node;
using namespace v8;


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

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

              

  private:

    struct CherrypickBaton {
      int error_code;
      const git_error* error;
      git_repository * repo;
      git_commit * commit;
      const git_cherrypick_options * cherrypick_options;
     };
    class CherrypickWorker : public nodegit::AsyncWorker {
      public:
        CherrypickWorker(
            CherrypickBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitCherrypick:Cherrypick", cleanupHandles)
          , baton(_baton) {};
        CherrypickWorker(const CherrypickWorker &) = delete;
        CherrypickWorker(CherrypickWorker &&) = delete;
        CherrypickWorker &operator=(const CherrypickWorker &) = delete;
        CherrypickWorker &operator=(CherrypickWorker &&) = delete;
        ~CherrypickWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        CherrypickBaton *baton;
    };

    static NAN_METHOD(Cherrypick);

    struct CommitBaton {
      int error_code;
      const git_error* error;
      git_index * out;
      git_repository * repo;
      git_commit * cherrypick_commit;
      git_commit * our_commit;
      unsigned int mainline;
      const git_merge_options * merge_options;
     };
    class CommitWorker : public nodegit::AsyncWorker {
      public:
        CommitWorker(
            CommitBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitCherrypick:Commit", cleanupHandles)
          , baton(_baton) {};
        CommitWorker(const CommitWorker &) = delete;
        CommitWorker(CommitWorker &&) = delete;
        CommitWorker &operator=(const CommitWorker &) = delete;
        CommitWorker &operator=(CommitWorker &&) = delete;
        ~CommitWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        CommitBaton *baton;
    };

    static NAN_METHOD(Commit);
};

#endif
