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

#ifndef GITODB_H
#define GITODB_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/odb_object.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:
    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
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitOdb:AddDiskAlternate")
          , baton(_baton) {};
        ~AddDiskAlternateWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        AddDiskAlternateBaton *baton;
    };

    static NAN_METHOD(AddDiskAlternate);

    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
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitOdb:ExistsPrefix")
          , baton(_baton) {};
        ~ExistsPrefixWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        ExistsPrefixBaton *baton;
    };

    static NAN_METHOD(ExistsPrefix);

    struct HashfileBaton {
      int error_code;
      const git_error* error;
      git_oid * out;
      const char * path;
      git_object_t type;
    };
    class HashfileWorker : public nodegit::AsyncWorker {
      public:
        HashfileWorker(
            HashfileBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitOdb:Hashfile")
          , baton(_baton) {};
        ~HashfileWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        HashfileBaton *baton;
    };

    static NAN_METHOD(Hashfile);

    struct OpenBaton {
      int error_code;
      const git_error* error;
      git_odb * out;
      const char * objects_dir;
    };
    class OpenWorker : public nodegit::AsyncWorker {
      public:
        OpenWorker(
            OpenBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitOdb:Open")
          , baton(_baton) {};
        ~OpenWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        OpenBaton *baton;
    };

    static NAN_METHOD(Open);

    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
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitOdb:OdbRead")
          , baton(_baton) {};
        ~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
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitOdb:ReadPrefix")
          , baton(_baton) {};
        ~ReadPrefixWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        ReadPrefixBaton *baton;
    };

    static NAN_METHOD(ReadPrefix);

    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
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitOdb:Write")
          , baton(_baton) {};
        ~WriteWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        WriteBaton *baton;
    };

    static NAN_METHOD(Write);
};

#endif
