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

#ifndef GITODB_H
#define GITODB_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/oid.h"
#include "../include/odb_object.h"
#include "../include/commit_graph.h"
// Forward declaration.
struct git_odb {
};

using namespace node;
using namespace v8;

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

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

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

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

                                         

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

    struct AddDiskAlternateBaton {
      int error_code;
      const git_error* error;
      git_odb * odb;
      const char * path;
     };
    class AddDiskAlternateWorker : public nodegit::AsyncWorker {
      public:
        AddDiskAlternateWorker(
            AddDiskAlternateBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitOdb:AddDiskAlternate", cleanupHandles)
          , baton(_baton) {};
        AddDiskAlternateWorker(const AddDiskAlternateWorker &) = delete;
        AddDiskAlternateWorker(AddDiskAlternateWorker &&) = delete;
        AddDiskAlternateWorker &operator=(const AddDiskAlternateWorker &) = delete;
        AddDiskAlternateWorker &operator=(AddDiskAlternateWorker &&) = delete;
        ~AddDiskAlternateWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        AddDiskAlternateBaton *baton;
    };

    static NAN_METHOD(AddDiskAlternate);

    static NAN_METHOD(ExistsExt);

    struct ExistsPrefixBaton {
      int error_code;
      const git_error* error;
      git_oid * out;
      git_odb * db;
      const git_oid * short_id;
      bool short_idNeedsFree;
      size_t len;
     };
    class ExistsPrefixWorker : public nodegit::AsyncWorker {
      public:
        ExistsPrefixWorker(
            ExistsPrefixBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitOdb:ExistsPrefix", cleanupHandles)
          , baton(_baton) {};
        ExistsPrefixWorker(const ExistsPrefixWorker &) = delete;
        ExistsPrefixWorker(ExistsPrefixWorker &&) = delete;
        ExistsPrefixWorker &operator=(const ExistsPrefixWorker &) = delete;
        ExistsPrefixWorker &operator=(ExistsPrefixWorker &&) = delete;
        ~ExistsPrefixWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        ExistsPrefixBaton *baton;
    };

    static NAN_METHOD(ExistsPrefix);

    struct OdbReadBaton {
      int error_code;
      const git_error* error;
      git_odb_object * out;
      git_odb * db;
      const git_oid * id;
      bool idNeedsFree;
     };
    class OdbReadWorker : public nodegit::AsyncWorker {
      public:
        OdbReadWorker(
            OdbReadBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitOdb:OdbRead", cleanupHandles)
          , baton(_baton) {};
        OdbReadWorker(const OdbReadWorker &) = delete;
        OdbReadWorker(OdbReadWorker &&) = delete;
        OdbReadWorker &operator=(const OdbReadWorker &) = delete;
        OdbReadWorker &operator=(OdbReadWorker &&) = delete;
        ~OdbReadWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        OdbReadBaton *baton;
    };

    static NAN_METHOD(OdbRead);

    struct ReadPrefixBaton {
      int error_code;
      const git_error* error;
      git_odb_object * out;
      git_odb * db;
      const git_oid * short_id;
      bool short_idNeedsFree;
      size_t len;
     };
    class ReadPrefixWorker : public nodegit::AsyncWorker {
      public:
        ReadPrefixWorker(
            ReadPrefixBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitOdb:ReadPrefix", cleanupHandles)
          , baton(_baton) {};
        ReadPrefixWorker(const ReadPrefixWorker &) = delete;
        ReadPrefixWorker(ReadPrefixWorker &&) = delete;
        ReadPrefixWorker &operator=(const ReadPrefixWorker &) = delete;
        ReadPrefixWorker &operator=(ReadPrefixWorker &&) = delete;
        ~ReadPrefixWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        ReadPrefixBaton *baton;
    };

    static NAN_METHOD(ReadPrefix);

    static NAN_METHOD(SetCommitGraph);

    struct WriteBaton {
      int error_code;
      const git_error* error;
      git_oid * out;
      git_odb * odb;
      const void * data;
      size_t len;
      git_object_t type;
     };
    class WriteWorker : public nodegit::AsyncWorker {
      public:
        WriteWorker(
            WriteBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitOdb:Write", cleanupHandles)
          , baton(_baton) {};
        WriteWorker(const WriteWorker &) = delete;
        WriteWorker(WriteWorker &&) = delete;
        WriteWorker &operator=(const WriteWorker &) = delete;
        WriteWorker &operator=(WriteWorker &&) = delete;
        ~WriteWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        WriteBaton *baton;
    };

    static NAN_METHOD(Write);

    static NAN_METHOD(WriteMultiPackIndex);
};

#endif
