#ifndef GITCRED_H
#define GITCRED_H
// generated from class_header.h
#include <nan.h>
#include <string>

extern "C" {
#include <git2.h>
}

#include "../include/cred.h"

using namespace node;
using namespace v8;

class GitCred : public ObjectWrap {
public:

  static Persistent<Function> constructor_template;
  static void InitializeComponent (Handle<v8::Object> target);

  git_cred *GetValue();
  git_cred **GetRefValue();

  static Handle<Value> New(void *raw, bool selfFreeing);
  bool selfFreeing;

private:
  GitCred(git_cred *raw, bool selfFreeing);
  ~GitCred();

  static NAN_METHOD(JSNewFunction);


  struct DefaultNewBaton {
    int error_code;
    const git_error* error;
    git_cred * out;
  };
  class DefaultNewWorker : public NanAsyncWorker {
  public:
    DefaultNewWorker(
      DefaultNewBaton *_baton,
      NanCallback *callback
    ) : NanAsyncWorker(callback)
      , baton(_baton) {};
    ~DefaultNewWorker() {};
    void Execute();
    void HandleOKCallback();

  private:
    DefaultNewBaton *baton;
  };

  static NAN_METHOD(DefaultNew);

  static NAN_METHOD(HasUsername);

  static NAN_METHOD(SshKeyFromAgent);

  static NAN_METHOD(SshKeyNew);

  struct UserpassPlaintextNewBaton {
    int error_code;
    const git_error* error;
    git_cred * out;
    const char * username;
    const char * password;
  };
  class UserpassPlaintextNewWorker : public NanAsyncWorker {
  public:
    UserpassPlaintextNewWorker(
      UserpassPlaintextNewBaton *_baton,
      NanCallback *callback
    ) : NanAsyncWorker(callback)
      , baton(_baton) {};
    ~UserpassPlaintextNewWorker() {};
    void Execute();
    void HandleOKCallback();

  private:
    UserpassPlaintextNewBaton *baton;
  };

  static NAN_METHOD(UserpassPlaintextNew);
  git_cred *raw;
};

#endif
