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

#ifndef GITOBJECT_H
#define GITOBJECT_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/repository.h"
#include "../include/buf.h"
// Forward declaration.
struct git_object {
};

using namespace node;
using namespace v8;

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

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

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

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

                                                            

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

    static NAN_METHOD(Size);

    struct DupBaton {
      int error_code;
      const git_error* error;
      git_object * dest;
      git_object * source;
     };
    class DupWorker : public nodegit::AsyncWorker {
      public:
        DupWorker(
            DupBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitObject:Dup", cleanupHandles)
          , baton(_baton) {};
        DupWorker(const DupWorker &) = delete;
        DupWorker(DupWorker &&) = delete;
        DupWorker &operator=(const DupWorker &) = delete;
        DupWorker &operator=(DupWorker &&) = delete;
        ~DupWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        DupBaton *baton;
    };

    static NAN_METHOD(Dup);

    static NAN_METHOD(Id);

    struct LookupBaton {
      int error_code;
      const git_error* error;
      git_object * object;
      git_repository * repo;
      const git_oid * id;
      bool idNeedsFree;
      git_object_t type;
     };
    class LookupWorker : public nodegit::AsyncWorker {
      public:
        LookupWorker(
            LookupBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitObject:Lookup", cleanupHandles)
          , baton(_baton) {};
        LookupWorker(const LookupWorker &) = delete;
        LookupWorker(LookupWorker &&) = delete;
        LookupWorker &operator=(const LookupWorker &) = delete;
        LookupWorker &operator=(LookupWorker &&) = delete;
        ~LookupWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        LookupBaton *baton;
    };

    static NAN_METHOD(Lookup);

    struct LookupBypathBaton {
      int error_code;
      const git_error* error;
      git_object * out;
      const git_object * treeish;
      const char * path;
      git_object_t type;
     };
    class LookupBypathWorker : public nodegit::AsyncWorker {
      public:
        LookupBypathWorker(
            LookupBypathBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitObject:LookupBypath", cleanupHandles)
          , baton(_baton) {};
        LookupBypathWorker(const LookupBypathWorker &) = delete;
        LookupBypathWorker(LookupBypathWorker &&) = delete;
        LookupBypathWorker &operator=(const LookupBypathWorker &) = delete;
        LookupBypathWorker &operator=(LookupBypathWorker &&) = delete;
        ~LookupBypathWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        LookupBypathBaton *baton;
    };

    static NAN_METHOD(LookupBypath);

    struct LookupPrefixBaton {
      int error_code;
      const git_error* error;
      git_object * object_out;
      git_repository * repo;
      const git_oid * id;
      bool idNeedsFree;
      size_t len;
      git_object_t type;
     };
    class LookupPrefixWorker : public nodegit::AsyncWorker {
      public:
        LookupPrefixWorker(
            LookupPrefixBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitObject:LookupPrefix", cleanupHandles)
          , baton(_baton) {};
        LookupPrefixWorker(const LookupPrefixWorker &) = delete;
        LookupPrefixWorker(LookupPrefixWorker &&) = delete;
        LookupPrefixWorker &operator=(const LookupPrefixWorker &) = delete;
        LookupPrefixWorker &operator=(LookupPrefixWorker &&) = delete;
        ~LookupPrefixWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        LookupPrefixBaton *baton;
    };

    static NAN_METHOD(LookupPrefix);

    static NAN_METHOD(Owner);

    struct PeelBaton {
      int error_code;
      const git_error* error;
      git_object * peeled;
      const git_object * object;
      git_object_t target_type;
     };
    class PeelWorker : public nodegit::AsyncWorker {
      public:
        PeelWorker(
            PeelBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitObject:Peel", cleanupHandles)
          , baton(_baton) {};
        PeelWorker(const PeelWorker &) = delete;
        PeelWorker(PeelWorker &&) = delete;
        PeelWorker &operator=(const PeelWorker &) = delete;
        PeelWorker &operator=(PeelWorker &&) = delete;
        ~PeelWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        PeelBaton *baton;
    };

    static NAN_METHOD(Peel);

    static NAN_METHOD(RawcontentIsValid);

    struct ShortIdBaton {
      int error_code;
      const git_error* error;
      git_buf * out;
      const git_object * obj;
     };
    class ShortIdWorker : public nodegit::AsyncWorker {
      public:
        ShortIdWorker(
            ShortIdBaton *_baton,
            Nan::Callback *callback,
            std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> &cleanupHandles
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitObject:ShortId", cleanupHandles)
          , baton(_baton) {};
        ShortIdWorker(const ShortIdWorker &) = delete;
        ShortIdWorker(ShortIdWorker &&) = delete;
        ShortIdWorker &operator=(const ShortIdWorker &) = delete;
        ShortIdWorker &operator=(ShortIdWorker &&) = delete;
        ~ShortIdWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        ShortIdBaton *baton;
    };

    static NAN_METHOD(ShortId);

    static NAN_METHOD(String2type);

    static NAN_METHOD(Type);

    static NAN_METHOD(Type2string);

    static NAN_METHOD(Typeisloose);
};

#endif
