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

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


// generated from struct_content.cc
GitMergeOptions::GitMergeOptions() {
  git_merge_options wrappedValue = GIT_MERGE_OPTIONS_INIT;
  this->raw = (git_merge_options*) malloc(sizeof(git_merge_options));
  memcpy(this->raw, &wrappedValue, sizeof(git_merge_options));

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

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

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

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

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

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

      tpl->InstanceTemplate()->SetAccessor(NanNew<String>("version"), GetVersion, SetVersion);
       tpl->InstanceTemplate()->SetAccessor(NanNew<String>("flags"), GetFlags, SetFlags);
       tpl->InstanceTemplate()->SetAccessor(NanNew<String>("renameThreshold"), GetRenameThreshold, SetRenameThreshold);
       tpl->InstanceTemplate()->SetAccessor(NanNew<String>("targetLimit"), GetTargetLimit, SetTargetLimit);
       tpl->InstanceTemplate()->SetAccessor(NanNew<String>("fileFavor"), GetFileFavor, SetFileFavor);
  
  Local<Function> _constructor_template = tpl->GetFunction();
  NanAssignPersistent(constructor_template, _constructor_template);
  target->Set(NanNew<String>("MergeOptions"), _constructor_template);
}

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

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

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

  NanReturnValue(args.This());
}

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

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

git_merge_options *GitMergeOptions::GetValue() {
  return this->raw;
}

git_merge_options **GitMergeOptions::GetRefValue() {
  return &this->raw;
}

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

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

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

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

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

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

      NAN_GETTER(GitMergeOptions::GetFlags) {
      NanScope();

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

        NanReturnValue(NanNew((int)wrapper->GetValue()->flags));

     }

    NAN_SETTER(GitMergeOptions::SetFlags) {
      NanScope();

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

        if (value->IsNumber()) {
          wrapper->GetValue()->flags = (git_merge_tree_flag_t) value->Int32Value();
        }

     }

      NAN_GETTER(GitMergeOptions::GetRenameThreshold) {
      NanScope();

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

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

    NAN_SETTER(GitMergeOptions::SetRenameThreshold) {
      NanScope();

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

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

      NAN_GETTER(GitMergeOptions::GetTargetLimit) {
      NanScope();

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

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

    NAN_SETTER(GitMergeOptions::SetTargetLimit) {
      NanScope();

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

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

      NAN_GETTER(GitMergeOptions::GetFileFavor) {
      NanScope();

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

        NanReturnValue(NanNew((int)wrapper->GetValue()->file_favor));

     }

    NAN_SETTER(GitMergeOptions::SetFileFavor) {
      NanScope();

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

        if (value->IsNumber()) {
          wrapper->GetValue()->file_favor = (git_merge_file_favor_t) value->Int32Value();
        }

     }

   
Persistent<Function> GitMergeOptions::constructor_template;
