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

#ifndef GITMAILMAP_H
#define GITMAILMAP_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/signature.h"
// Forward declaration.
struct git_mailmap {
};

using namespace node;
using namespace v8;

class GitMailmap;
 
struct GitMailmapTraits {
  typedef GitMailmap cppClass;
  typedef git_mailmap cType;
 
  static const bool isDuplicable = false;
  static void duplicate(git_mailmap **dest, git_mailmap *src) {
     Nan::ThrowError("duplicate called on GitMailmap which cannot be duplicated");
   }

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

class GitMailmap : public
  NodeGitWrapper<GitMailmapTraits>
{
    // grant full access to base class
    friend class NodeGitWrapper<GitMailmapTraits>;
   public:
    GitMailmap(const GitMailmap &) = delete;
    GitMailmap(GitMailmap &&) = delete;
    GitMailmap &operator=(const GitMailmap &) = delete;
    GitMailmap &operator=(GitMailmap &&) = delete;

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

                                

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

    struct AddEntryBaton {
      int error_code;
      const git_error* error;
      git_mailmap * mm;
      const char * real_name;
      const char * real_email;
      const char * replace_name;
      const char * replace_email;
     };
    class AddEntryWorker : public nodegit::AsyncWorker {
      public:
        AddEntryWorker(
            AddEntryBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitMailmap:AddEntry", cleanupHandles)
          , baton(_baton) {};
        AddEntryWorker(const AddEntryWorker &) = delete;
        AddEntryWorker(AddEntryWorker &&) = delete;
        AddEntryWorker &operator=(const AddEntryWorker &) = delete;
        AddEntryWorker &operator=(AddEntryWorker &&) = delete;
        ~AddEntryWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        AddEntryBaton *baton;
    };

    static NAN_METHOD(AddEntry);

    struct FromBufferBaton {
      int error_code;
      const git_error* error;
      git_mailmap * out;
      const char * buf;
      size_t len;
     };
    class FromBufferWorker : public nodegit::AsyncWorker {
      public:
        FromBufferWorker(
            FromBufferBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitMailmap:FromBuffer", cleanupHandles)
          , baton(_baton) {};
        FromBufferWorker(const FromBufferWorker &) = delete;
        FromBufferWorker(FromBufferWorker &&) = delete;
        FromBufferWorker &operator=(const FromBufferWorker &) = delete;
        FromBufferWorker &operator=(FromBufferWorker &&) = delete;
        ~FromBufferWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        FromBufferBaton *baton;
    };

    static NAN_METHOD(FromBuffer);

    struct FromRepositoryBaton {
      int error_code;
      const git_error* error;
      git_mailmap * out;
      git_repository * repo;
     };
    class FromRepositoryWorker : public nodegit::AsyncWorker {
      public:
        FromRepositoryWorker(
            FromRepositoryBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitMailmap:FromRepository", cleanupHandles)
          , baton(_baton) {};
        FromRepositoryWorker(const FromRepositoryWorker &) = delete;
        FromRepositoryWorker(FromRepositoryWorker &&) = delete;
        FromRepositoryWorker &operator=(const FromRepositoryWorker &) = delete;
        FromRepositoryWorker &operator=(FromRepositoryWorker &&) = delete;
        ~FromRepositoryWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        FromRepositoryBaton *baton;
    };

    static NAN_METHOD(FromRepository);

    struct CreateBaton {
      int error_code;
      const git_error* error;
      git_mailmap * out;
     };
    class CreateWorker : public nodegit::AsyncWorker {
      public:
        CreateWorker(
            CreateBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitMailmap:Create", cleanupHandles)
          , baton(_baton) {};
        CreateWorker(const CreateWorker &) = delete;
        CreateWorker(CreateWorker &&) = delete;
        CreateWorker &operator=(const CreateWorker &) = delete;
        CreateWorker &operator=(CreateWorker &&) = delete;
        ~CreateWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        CreateBaton *baton;
    };

    static NAN_METHOD(Create);

    struct ResolveBaton {
      int error_code;
      const git_error* error;
      const char * real_name;
      const char * real_email;
      const git_mailmap * mm;
      const char * name;
      const char * email;
     };
    class ResolveWorker : public nodegit::AsyncWorker {
      public:
        ResolveWorker(
            ResolveBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitMailmap:Resolve", cleanupHandles)
          , baton(_baton) {};
        ResolveWorker(const ResolveWorker &) = delete;
        ResolveWorker(ResolveWorker &&) = delete;
        ResolveWorker &operator=(const ResolveWorker &) = delete;
        ResolveWorker &operator=(ResolveWorker &&) = delete;
        ~ResolveWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        ResolveBaton *baton;
    };

    static NAN_METHOD(Resolve);

    struct ResolveSignatureBaton {
      int error_code;
      const git_error* error;
      git_signature * out;
      const git_mailmap * mm;
      const git_signature * sig;
     };
    class ResolveSignatureWorker : public nodegit::AsyncWorker {
      public:
        ResolveSignatureWorker(
            ResolveSignatureBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitMailmap:ResolveSignature", cleanupHandles)
          , baton(_baton) {};
        ResolveSignatureWorker(const ResolveSignatureWorker &) = delete;
        ResolveSignatureWorker(ResolveSignatureWorker &&) = delete;
        ResolveSignatureWorker &operator=(const ResolveSignatureWorker &) = delete;
        ResolveSignatureWorker &operator=(ResolveSignatureWorker &&) = delete;
        ~ResolveSignatureWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        ResolveSignatureBaton *baton;
    };

    static NAN_METHOD(ResolveSignature);
};

#endif
