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

#ifndef GITMERGE_H
#define GITMERGE_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/repository.h"
#include "../include/annotated_commit.h"
#include "../include/merge_options.h"
#include "../include/checkout_options.h"
#include "../include/reference.h"
#include "../include/oid.h"
#include "../include/oidarray.h"
#include "../include/index.h"
#include "../include/commit.h"
#include "../include/tree.h"

using namespace node;
using namespace v8;


class GitMerge : public
  Nan::ObjectWrap
{
   public:
    static void InitializeComponent (v8::Local<v8::Object> target, nodegit::Context *nodegitContext);

                                                  

  private:

    struct MergeBaton {
      int error_code;
      const git_error* error;
      git_repository * repo;
      const git_annotated_commit ** their_heads;
      size_t their_heads_len;
      git_merge_options * merge_opts;
      git_checkout_options * checkout_opts;
    };
    class MergeWorker : public nodegit::AsyncWorker {
      public:
        MergeWorker(
            MergeBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitMerge:Merge")
          , baton(_baton) {};
        ~MergeWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        MergeBaton *baton;
    };

    static NAN_METHOD(Merge);

    struct AnalysisBaton {
      int error_code;
      const git_error* error;
      git_merge_analysis_t * analysis_out;
      git_merge_preference_t * preference_out;
      git_repository * repo;
      const git_annotated_commit ** their_heads;
      size_t their_heads_len;
    };
    class AnalysisWorker : public nodegit::AsyncWorker {
      public:
        AnalysisWorker(
            AnalysisBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitMerge:Analysis")
          , baton(_baton) {};
        ~AnalysisWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        AnalysisBaton *baton;
    };

    static NAN_METHOD(Analysis);

    struct AnalysisForRefBaton {
      int error_code;
      const git_error* error;
      git_merge_analysis_t * analysis_out;
      git_merge_preference_t * preference_out;
      git_repository * repo;
      git_reference * our_ref;
      const git_annotated_commit ** their_heads;
      size_t their_heads_len;
    };
    class AnalysisForRefWorker : public nodegit::AsyncWorker {
      public:
        AnalysisForRefWorker(
            AnalysisForRefBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitMerge:AnalysisForRef")
          , baton(_baton) {};
        ~AnalysisForRefWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        AnalysisForRefBaton *baton;
    };

    static NAN_METHOD(AnalysisForRef);

    struct BaseBaton {
      int error_code;
      const git_error* error;
      git_oid * out;
      git_repository * repo;
      const git_oid * one;
      bool oneNeedsFree;
      const git_oid * two;
      bool twoNeedsFree;
    };
    class BaseWorker : public nodegit::AsyncWorker {
      public:
        BaseWorker(
            BaseBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitMerge:Base")
          , baton(_baton) {};
        ~BaseWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        BaseBaton *baton;
    };

    static NAN_METHOD(Base);

    struct BasesBaton {
      int error_code;
      const git_error* error;
      git_oidarray * out;
      git_repository * repo;
      const git_oid * one;
      bool oneNeedsFree;
      const git_oid * two;
      bool twoNeedsFree;
    };
    class BasesWorker : public nodegit::AsyncWorker {
      public:
        BasesWorker(
            BasesBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitMerge:Bases")
          , baton(_baton) {};
        ~BasesWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        BasesBaton *baton;
    };

    static NAN_METHOD(Bases);

    struct CommitsBaton {
      int error_code;
      const git_error* error;
      git_index * out;
      git_repository * repo;
      const git_commit * our_commit;
      const git_commit * their_commit;
      const git_merge_options * opts;
    };
    class CommitsWorker : public nodegit::AsyncWorker {
      public:
        CommitsWorker(
            CommitsBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitMerge:Commits")
          , baton(_baton) {};
        ~CommitsWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        CommitsBaton *baton;
    };

    static NAN_METHOD(Commits);

    struct TreesBaton {
      int error_code;
      const git_error* error;
      git_index * out;
      git_repository * repo;
      const git_tree * ancestor_tree;
      const git_tree * our_tree;
      const git_tree * their_tree;
      const git_merge_options * opts;
    };
    class TreesWorker : public nodegit::AsyncWorker {
      public:
        TreesWorker(
            TreesBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitMerge:Trees")
          , baton(_baton) {};
        ~TreesWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        TreesBaton *baton;
    };

    static NAN_METHOD(Trees);
};

#endif
