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

#ifndef GITCREDENTIAL_H
#define GITCREDENTIAL_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"


using namespace node;
using namespace v8;

class GitCredential;

struct GitCredentialTraits {
  typedef GitCredential cppClass;
  typedef git_credential cType;

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

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

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

                                     

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

    static NAN_METHOD(DefaultNew);

    static NAN_METHOD(GetUsername);

    static NAN_METHOD(HasUsername);

    static NAN_METHOD(SshKeyFromAgent);

    struct SshKeyMemoryNewBaton {
      int error_code;
      const git_error* error;
      git_credential * out;
      const char * username;
      const char * publickey;
      const char * privatekey;
      const char * passphrase;
    };
    class SshKeyMemoryNewWorker : public nodegit::AsyncWorker {
      public:
        SshKeyMemoryNewWorker(
            SshKeyMemoryNewBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitCredential:SshKeyMemoryNew")
          , baton(_baton) {};
        ~SshKeyMemoryNewWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        SshKeyMemoryNewBaton *baton;
    };

    static NAN_METHOD(SshKeyMemoryNew);

    static NAN_METHOD(SshKeyNew);

    struct UsernameNewBaton {
      int error_code;
      const git_error* error;
      git_credential * out;
      const char * username;
    };
    class UsernameNewWorker : public nodegit::AsyncWorker {
      public:
        UsernameNewWorker(
            UsernameNewBaton *_baton,
            Nan::Callback *callback
        ) : nodegit::AsyncWorker(callback, "nodegit:AsyncWorker:GitCredential:UsernameNew")
          , baton(_baton) {};
        ~UsernameNewWorker() {};
        void Execute();
        void HandleErrorCallback();
        void HandleOKCallback();
        nodegit::LockMaster AcquireLocks();

      private:
        UsernameNewBaton *baton;
    };

    static NAN_METHOD(UsernameNew);

    static NAN_METHOD(UserpassPlaintextNew);
};

#endif
