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

#ifndef GITNOTE_H
#define GITNOTE_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/signature.h"
#include "../include/oid.h"
#include "../include/repository.h"
#include "../include/commit.h"
#include "../include/note_iterator.h"
#include "../include/buf.h"
// Forward declaration.
struct git_note {
};

using namespace node;
using namespace v8;

class GitNote;

struct GitNoteTraits {
  typedef GitNote cppClass;
  typedef git_note cType;

  static const bool isDuplicable = false;
  static void duplicate(git_note **dest, git_note *src) {
     Nan::ThrowError("duplicate called on GitNote which cannot be duplicated");
   }

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

class GitNote : public
  NodeGitWrapper<GitNoteTraits>
{
    // grant full access to base class
    friend class NodeGitWrapper<GitNoteTraits>;
   public:
    static void InitializeComponent (v8::Local<v8::Object> target, nodegit::Context *nodegitContext);

                                                       static int Foreach_note_cb_cppCallback (
      const git_oid * blob_id
      ,
       const git_oid * annotated_object_id
      ,
       void * payload
      );

    static void Foreach_note_cb_cancelAsync(void *baton);
    static void Foreach_note_cb_async(void *baton);
    static void Foreach_note_cb_promiseCompleted(bool isFulfilled, nodegit::AsyncBaton *_baton, v8::Local<v8::Value> result);
    class Foreach_NoteCbBaton : public nodegit::AsyncBatonWithResult<int> {
    public:
      const git_oid * blob_id;
      const git_oid * annotated_object_id;
      void * payload;
 
      Foreach_NoteCbBaton(const int &defaultResult)
        : nodegit::AsyncBatonWithResult<int>(defaultResult) {
        }
    };
                        

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

    static NAN_METHOD(Author);

    static NAN_METHOD(CommitCreate);

    struct CommitIteratorNewBaton {
      int error_code;
      const git_error* error;
      git_note_iterator * out;
      git_commit * notes_commit;
    };
    class CommitIteratorNewWorker : public nodegit::AsyncWorker {
      public:
        CommitIteratorNewWorker(
            CommitIteratorNewBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitNote:CommitIteratorNew")
          , baton(_baton) {};
        ~CommitIteratorNewWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        CommitIteratorNewBaton *baton;
    };

    static NAN_METHOD(CommitIteratorNew);

    struct CommitReadBaton {
      int error_code;
      const git_error* error;
      git_note * out;
      git_repository * repo;
      git_commit * notes_commit;
      const git_oid * oid;
      bool oidNeedsFree;
    };
    class CommitReadWorker : public nodegit::AsyncWorker {
      public:
        CommitReadWorker(
            CommitReadBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitNote:CommitRead")
          , baton(_baton) {};
        ~CommitReadWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        CommitReadBaton *baton;
    };

    static NAN_METHOD(CommitRead);

    struct CommitRemoveBaton {
      int error_code;
      const git_error* error;
      git_oid * notes_commit_out;
      git_repository * repo;
      git_commit * notes_commit;
      const git_signature * author;
      const git_signature * committer;
      const git_oid * oid;
      bool oidNeedsFree;
    };
    class CommitRemoveWorker : public nodegit::AsyncWorker {
      public:
        CommitRemoveWorker(
            CommitRemoveBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitNote:CommitRemove")
          , baton(_baton) {};
        ~CommitRemoveWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        CommitRemoveBaton *baton;
    };

    static NAN_METHOD(CommitRemove);

    static NAN_METHOD(Committer);

    struct CreateBaton {
      int error_code;
      const git_error* error;
      git_oid * out;
      git_repository * repo;
      const char * notes_ref;
      const git_signature * author;
      const git_signature * committer;
      const git_oid * oid;
      bool oidNeedsFree;
      const char * note;
      int force;
    };
    class CreateWorker : public nodegit::AsyncWorker {
      public:
        CreateWorker(
            CreateBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitNote:Create")
          , baton(_baton) {};
        ~CreateWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        CreateBaton *baton;
    };

    static NAN_METHOD(Create);

    struct DefaultRefBaton {
      int error_code;
      const git_error* error;
      git_buf * out;
      git_repository * repo;
    };
    class DefaultRefWorker : public nodegit::AsyncWorker {
      public:
        DefaultRefWorker(
            DefaultRefBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitNote:DefaultRef")
          , baton(_baton) {};
        ~DefaultRefWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        DefaultRefBaton *baton;
    };

    static NAN_METHOD(DefaultRef);

    struct ForeachBaton {
      int error_code;
      const git_error* error;
      git_repository * repo;
      const char * notes_ref;
      git_note_foreach_cb note_cb;
      void * payload;
    };
    class ForeachWorker : public nodegit::AsyncWorker {
      public:
        ForeachWorker(
            ForeachBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitNote:Foreach")
          , baton(_baton) {};
        ~ForeachWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        ForeachBaton *baton;
    };

    static NAN_METHOD(Foreach);

    static NAN_METHOD(Id);

    static NAN_METHOD(Message);

    struct ReadBaton {
      int error_code;
      const git_error* error;
      git_note * out;
      git_repository * repo;
      const char * notes_ref;
      const git_oid * oid;
      bool oidNeedsFree;
    };
    class ReadWorker : public nodegit::AsyncWorker {
      public:
        ReadWorker(
            ReadBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitNote:Read")
          , baton(_baton) {};
        ~ReadWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        ReadBaton *baton;
    };

    static NAN_METHOD(Read);

    struct RemoveBaton {
      int error_code;
      const git_error* error;
      git_repository * repo;
      const char * notes_ref;
      const git_signature * author;
      const git_signature * committer;
      const git_oid * oid;
      bool oidNeedsFree;
    };
    class RemoveWorker : public nodegit::AsyncWorker {
      public:
        RemoveWorker(
            RemoveBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitNote:Remove")
          , baton(_baton) {};
        ~RemoveWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        RemoveBaton *baton;
    };

    static NAN_METHOD(Remove);

    struct Foreach_globalPayload {
      Nan::Callback * note_cb;

      Foreach_globalPayload() {
        note_cb = NULL;
      }

      ~Foreach_globalPayload() {
        if (note_cb != NULL) {
          delete note_cb;
        }
      }
    };
};

#endif
