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

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

#include <iostream>
#include "../include/functions/copy.h"
#include "../include/push_options.h"


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


// generated from struct_content.cc
GitPushOptions::GitPushOptions()
{
  git_push_options wrappedValue = GIT_PUSH_OPTIONS_INIT;
  this->raw = (git_push_options*) malloc(sizeof(git_push_options));
  memcpy(this->raw, &wrappedValue, sizeof(git_push_options));

  this->ConstructFields();
  this->selfFreeing = true;
}

GitPushOptions::GitPushOptions(git_push_options* raw, bool selfFreeing)
{
  this->raw = raw;
  this->ConstructFields();
  this->selfFreeing = selfFreeing;
}

GitPushOptions::~GitPushOptions()
{
  // This is going to cause memory leaks. We'll have to solve that later
  // TODO: Clean up memory better
  if (this->selfFreeing) {
    free(this->raw);
  }
}

void GitPushOptions::ConstructFields()
{
}

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

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

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

  tpl->InstanceTemplate()->SetAccessor(NanNew<String>("version"), GetVersion, SetVersion);
  tpl->InstanceTemplate()->SetAccessor(NanNew<String>("pbParallelism"), GetPbParallelism, SetPbParallelism);

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

NAN_METHOD(GitPushOptions::JSNewFunction)
{
  NanScope();
  GitPushOptions* instance;

  if (args.Length() == 0 || !args[0]->IsExternal()) {
    instance = new GitPushOptions();
  } else {
    instance = new GitPushOptions(static_cast<git_push_options*>(Handle<External>::Cast(args[0])->Value()), args[1]->BooleanValue());
  }

  instance->Wrap(args.This());

  NanReturnValue(args.This());
}

Handle<Value> GitPushOptions::New(void* raw, bool selfFreeing)
{
  NanEscapableScope();

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

git_push_options *GitPushOptions::GetValue()
{
  return this->raw;
}

git_push_options **GitPushOptions::GetRefValue()
{
  return &this->raw;
}

NAN_GETTER(GitPushOptions::GetVersion)
{
  NanScope();

  GitPushOptions *wrapper = ObjectWrap::Unwrap<GitPushOptions>(args.This());

  NanReturnValue(NanNew<Number>(wrapper->GetValue()->version));
}

NAN_SETTER(GitPushOptions::SetVersion)
{
  NanScope();

  GitPushOptions *wrapper = ObjectWrap::Unwrap<GitPushOptions>(args.This());

  if (value->IsNumber()) {
    wrapper->GetValue()->version = (unsigned int) value->Int32Value();
  }
}

NAN_GETTER(GitPushOptions::GetPbParallelism)
{
  NanScope();

  GitPushOptions *wrapper = ObjectWrap::Unwrap<GitPushOptions>(args.This());

  NanReturnValue(NanNew<Number>(wrapper->GetValue()->pb_parallelism));
}

NAN_SETTER(GitPushOptions::SetPbParallelism)
{
  NanScope();

  GitPushOptions *wrapper = ObjectWrap::Unwrap<GitPushOptions>(args.This());

  if (value->IsNumber()) {
    wrapper->GetValue()->pb_parallelism = (unsigned int) value->Int32Value();
  }
}


Persistent<Function> GitPushOptions::constructor_template;
