// 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/merge_file_input.h"

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


// generated from struct_content.cc
GitMergeFileInput::GitMergeFileInput() {
  git_merge_file_input wrappedValue = GIT_MERGE_FILE_INPUT_INIT;
  this->raw = (git_merge_file_input*) malloc(sizeof(git_merge_file_input));
  memcpy(this->raw, &wrappedValue, sizeof(git_merge_file_input));

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

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

GitMergeFileInput::~GitMergeFileInput() {
  // 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 GitMergeFileInput::ConstructFields() {
                }

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

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

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

      tpl->InstanceTemplate()->SetAccessor(NanNew<String>("version"), GetVersion, SetVersion);
       tpl->InstanceTemplate()->SetAccessor(NanNew<String>("ptr"), GetPtr, SetPtr);
       tpl->InstanceTemplate()->SetAccessor(NanNew<String>("size"), GetSize, SetSize);
       tpl->InstanceTemplate()->SetAccessor(NanNew<String>("path"), GetPath, SetPath);
       tpl->InstanceTemplate()->SetAccessor(NanNew<String>("mode"), GetMode, SetMode);
  
  Local<Function> _constructor_template = tpl->GetFunction();
  NanAssignPersistent(constructor_template, _constructor_template);
  target->Set(NanNew<String>("MergeFileInput"), _constructor_template);
}

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

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

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

  NanReturnValue(args.This());
}

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

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

git_merge_file_input *GitMergeFileInput::GetValue() {
  return this->raw;
}

git_merge_file_input **GitMergeFileInput::GetRefValue() {
  return &this->raw;
}

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

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

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

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

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

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

      NAN_GETTER(GitMergeFileInput::GetPtr) {
      NanScope();

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

        if (wrapper->GetValue()->ptr) {
          NanReturnValue(NanNew<String>(wrapper->GetValue()->ptr));
        }
        else {
          NanReturnUndefined();
        }

     }

    NAN_SETTER(GitMergeFileInput::SetPtr) {
      NanScope();

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

        if (wrapper->GetValue()->ptr) {
        }

        String::Utf8Value str(value);
        wrapper->GetValue()->ptr = strdup(*str);

     }

      NAN_GETTER(GitMergeFileInput::GetSize) {
      NanScope();

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

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

    NAN_SETTER(GitMergeFileInput::SetSize) {
      NanScope();

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

         if (value->IsNumber()) {
          wrapper->GetValue()->size = (size_t) value->Int32Value();
        }
     }

      NAN_GETTER(GitMergeFileInput::GetPath) {
      NanScope();

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

        if (wrapper->GetValue()->path) {
          NanReturnValue(NanNew<String>(wrapper->GetValue()->path));
        }
        else {
          NanReturnUndefined();
        }

     }

    NAN_SETTER(GitMergeFileInput::SetPath) {
      NanScope();

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

        if (wrapper->GetValue()->path) {
        }

        String::Utf8Value str(value);
        wrapper->GetValue()->path = strdup(*str);

     }

      NAN_GETTER(GitMergeFileInput::GetMode) {
      NanScope();

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

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

    NAN_SETTER(GitMergeFileInput::SetMode) {
      NanScope();

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

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

   
Persistent<Function> GitMergeFileInput::constructor_template;
