// This is a generated file, modify: generate/templates/templates/struct_content.cc

#include <nan.h>
#include <string.h>
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif // win32

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

#include <iostream>
#include "../include/nodegit.h"
#include "../include/lock_master.h"
#include "../include/functions/copy.h"
#include "../include/push_options.h"
#include "nodegit_wrapper.cc"

  #include "../include/str_array_converter.h"
  #include "../include/remote_callbacks.h"
  #include "../include/proxy_options.h"
  #include "../include/strarray.h"
 
using namespace v8;
using namespace node;
using namespace std;


// generated from struct_content.cc
GitPushOptions::GitPushOptions() : NodeGitWrapper<GitPushOptionsTraits>(NULL, true, v8::Local<v8::Object>())
{
        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();
}

GitPushOptions::GitPushOptions(git_push_options* raw, bool selfFreeing, v8::Local<v8::Object> owner)
 : NodeGitWrapper<GitPushOptionsTraits>(raw, selfFreeing, owner)
{
  this->ConstructFields();
}

GitPushOptions::~GitPushOptions() {
                this->callbacks.Reset();
             this->proxy_opts.Reset();
             this->custom_headers.Reset();
    }

void GitPushOptions::ConstructFields() {
                v8::Local<Object> callbacksTemp = Nan::To<v8::Object>(GitRemoteCallbacks::New(
&this->raw->callbacks,
            false
          )).ToLocalChecked();
          this->callbacks.Reset(callbacksTemp);

             v8::Local<Object> proxy_optsTemp = Nan::To<v8::Object>(GitProxyOptions::New(
&this->raw->proxy_opts,
            false
          )).ToLocalChecked();
          this->proxy_opts.Reset(proxy_optsTemp);

             v8::Local<Object> custom_headersTemp = Nan::To<v8::Object>(GitStrarray::New(
&this->raw->custom_headers,
            false
          )).ToLocalChecked();
          this->custom_headers.Reset(custom_headersTemp);

    }

void GitPushOptions::InitializeComponent(Local<Object> target, nodegit::Context *nodegitContext) {
  Nan::HandleScope scope;

  Local<External> nodegitExternal = Nan::New<External>(nodegitContext);
  Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(JSNewFunction, nodegitExternal);

  tpl->InstanceTemplate()->SetInternalFieldCount(1);
  tpl->SetClassName(Nan::New("PushOptions").ToLocalChecked());

      Nan::SetAccessor(tpl->InstanceTemplate(), Nan::New("version").ToLocalChecked(), GetVersion, SetVersion, nodegitExternal);
        Nan::SetAccessor(tpl->InstanceTemplate(), Nan::New("pbParallelism").ToLocalChecked(), GetPbParallelism, SetPbParallelism, nodegitExternal);
        Nan::SetAccessor(tpl->InstanceTemplate(), Nan::New("callbacks").ToLocalChecked(), GetCallbacks, SetCallbacks, nodegitExternal);
        Nan::SetAccessor(tpl->InstanceTemplate(), Nan::New("proxyOpts").ToLocalChecked(), GetProxyOpts, SetProxyOpts, nodegitExternal);
        Nan::SetAccessor(tpl->InstanceTemplate(), Nan::New("customHeaders").ToLocalChecked(), GetCustomHeaders, SetCustomHeaders, nodegitExternal);
   
  InitializeTemplate(tpl);

  v8::Local<Function> constructor_template = Nan::GetFunction(tpl).ToLocalChecked();
  nodegitContext->SaveToPersistent("GitPushOptions::Template", constructor_template);
  Nan::Set(target, Nan::New("PushOptions").ToLocalChecked(), constructor_template);
}

    NAN_GETTER(GitPushOptions::GetVersion) {

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

        info.GetReturnValue().Set(Nan::New<Number>(wrapper->GetValue()->version));
     }

    NAN_SETTER(GitPushOptions::SetVersion) {
      GitPushOptions *wrapper = Nan::ObjectWrap::Unwrap<GitPushOptions>(info.This());

         if (value->IsNumber()) {
          wrapper->GetValue()->version = (unsigned int) Nan::To<int32_t>(value).FromJust();
        }
     }

      NAN_GETTER(GitPushOptions::GetPbParallelism) {

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

        info.GetReturnValue().Set(Nan::New<Number>(wrapper->GetValue()->pb_parallelism));
     }

    NAN_SETTER(GitPushOptions::SetPbParallelism) {
      GitPushOptions *wrapper = Nan::ObjectWrap::Unwrap<GitPushOptions>(info.This());

         if (value->IsNumber()) {
          wrapper->GetValue()->pb_parallelism = (unsigned int) Nan::To<int32_t>(value).FromJust();
        }
     }

      NAN_GETTER(GitPushOptions::GetCallbacks) {

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

        info.GetReturnValue().Set(Nan::New(wrapper->callbacks));

     }

    NAN_SETTER(GitPushOptions::SetCallbacks) {
      GitPushOptions *wrapper = Nan::ObjectWrap::Unwrap<GitPushOptions>(info.This());

        v8::Local<Object> callbacks(Nan::To<v8::Object>(value).ToLocalChecked());

        wrapper->callbacks.Reset(callbacks);

           auto wrappedObject = Nan::ObjectWrap::Unwrap<GitRemoteCallbacks>(callbacks);
          wrapper->raw->callbacks = * wrappedObject->GetValue();
          wrapper->AddReferenceCallbacks(
            2,
            [wrappedObject]() {
              wrappedObject->Reference();
            },
            [wrappedObject]() {
              wrappedObject->Unreference();
            }
          );
      }

      NAN_GETTER(GitPushOptions::GetProxyOpts) {

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

        info.GetReturnValue().Set(Nan::New(wrapper->proxy_opts));

     }

    NAN_SETTER(GitPushOptions::SetProxyOpts) {
      GitPushOptions *wrapper = Nan::ObjectWrap::Unwrap<GitPushOptions>(info.This());

        v8::Local<Object> proxy_opts(Nan::To<v8::Object>(value).ToLocalChecked());

        wrapper->proxy_opts.Reset(proxy_opts);

           auto wrappedObject = Nan::ObjectWrap::Unwrap<GitProxyOptions>(proxy_opts);
          wrapper->raw->proxy_opts = * wrappedObject->GetValue();
          wrapper->AddReferenceCallbacks(
            3,
            [wrappedObject]() {
              wrappedObject->Reference();
            },
            [wrappedObject]() {
              wrappedObject->Unreference();
            }
          );
      }

      NAN_GETTER(GitPushOptions::GetCustomHeaders) {

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

        info.GetReturnValue().Set(Nan::New(wrapper->custom_headers));

     }

    NAN_SETTER(GitPushOptions::SetCustomHeaders) {
      GitPushOptions *wrapper = Nan::ObjectWrap::Unwrap<GitPushOptions>(info.This());

        v8::Local<Object> custom_headers(Nan::To<v8::Object>(value).ToLocalChecked());

        wrapper->custom_headers.Reset(custom_headers);

          wrapper->raw->custom_headers = * StrArrayConverter::Convert(custom_headers);
      }

   
// force base class template instantiation, to make sure we get all the
// methods, statics, etc.
template class NodeGitWrapper<GitPushOptionsTraits>;
