// This is a generated file, modify: generate/templates/class_content.cc.
#include <nan.h>
#include <string.h>

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


#include "../include/functions/copy.h"
#include "../include/macros.h"
#include "../include/cred_userpass_payload.h"


#include <iostream>

using namespace std;
using namespace v8;
using namespace node;

GitCredUserpassPayload::GitCredUserpassPayload(git_cred_userpass_payload *raw, bool selfFreeing)
{
  this->raw = raw;
  this->selfFreeing = selfFreeing;
}

GitCredUserpassPayload::~GitCredUserpassPayload()
{
}

void GitCredUserpassPayload::InitializeComponent(Handle<v8::Object> target)
{
  NanScope();

  Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(JSNewFunction);

  tpl->InstanceTemplate()->SetInternalFieldCount(1);
  tpl->SetClassName(NanNew<String>("CredUserpassPayload"));

  NODE_SET_PROTOTYPE_METHOD(tpl, "username", Username);
  NODE_SET_PROTOTYPE_METHOD(tpl, "password", Password);

  Local<Function> _constructor_template = tpl->GetFunction();
  NanAssignPersistent(constructor_template, _constructor_template);
  target->Set(NanNew<String>("CredUserpassPayload"), _constructor_template);
}

NAN_METHOD(GitCredUserpassPayload::JSNewFunction)
{
  NanScope();

  if (args.Length() == 0 || !args[0]->IsExternal()) {
    return NanThrowError("A new GitCredUserpassPayload cannot be instantiated.");
  }

  GitCredUserpassPayload* object = new GitCredUserpassPayload(static_cast<git_cred_userpass_payload *>(Handle<External>::Cast(args[0])->Value()), args[1]->BooleanValue());
  object->Wrap(args.This());

  NanReturnValue(args.This());
}

Handle<Value> GitCredUserpassPayload::New(void *raw, bool selfFreeing)
{
  NanEscapableScope();
  Handle<Value> argv[2] = { NanNew<External>((void *)raw), NanNew<Boolean>(selfFreeing) };
  return NanEscapeScope(NanNew<Function>(GitCredUserpassPayload::constructor_template)->NewInstance(2, argv));
}

git_cred_userpass_payload *GitCredUserpassPayload::GetValue()
{
  return this->raw;
}

git_cred_userpass_payload **GitCredUserpassPayload::GetRefValue()
{
  return &this->raw;
}

NAN_METHOD(GitCredUserpassPayload::Username)
{
  NanScope();
  Handle<Value> to;

  char *  username =
    ObjectWrap::Unwrap<GitCredUserpassPayload>(args.This())->GetValue()->username;

// start convert_to_v8 block
  if (username) {
    to = NanNew<String>(username);
  } else {
    to = NanNull();
  }

  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitCredUserpassPayload::Password)
{
  NanScope();
  Handle<Value> to;

  char *  password =
    ObjectWrap::Unwrap<GitCredUserpassPayload>(args.This())->GetValue()->password;

// start convert_to_v8 block
  if (password) {
    to = NanNew<String>(password);
  } else {
    to = NanNull();
  }

  // end convert_to_v8 block
  NanReturnValue(to);
}
Persistent<Function> GitCredUserpassPayload::constructor_template;
