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

#include <nan.h>
#include <string.h>

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

#include "../include/nodegit.h"
#include "../include/lock_master.h"
#include "../include/functions/copy.h"
#include "../include/error.h"
#include "nodegit_wrapper.cc"

 
#include <iostream>

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

  GitError::~GitError() {
    // this will cause an error if you have a non-self-freeing object that also needs
    // to save values. Since the object that will eventually free the object has no
    // way of knowing to free these values.
     }

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

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

    tpl->InstanceTemplate()->SetInternalFieldCount(2);
    tpl->SetClassName(Nan::New("Error").ToLocalChecked());

          Nan::SetPrototypeMethod(tpl, "last", Last, nodegitExternal);
           Nan::SetPrototypeMethod(tpl, "message", Message, nodegitExternal);
         Nan::SetPrototypeMethod(tpl, "klass", Klass, nodegitExternal);
  
    InitializeTemplate(tpl);

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

  
/*
   * @return Error  result    */
NAN_METHOD(GitError::Last) {
  Nan::EscapableHandleScope scope;


  git_error_clear();

  { // lock master scope start
    nodegit::LockMaster lockMaster(
      /*asyncAction: */false
    );

 const git_error * result =     git_error_last(
    );

        // null checks on pointers
        if (!result) {
          return info.GetReturnValue().Set(scope.Escape(Nan::Undefined()));
        }

      v8::Local<v8::Value> v8ConversionSlot;
// start convert_to_v8 block
    if (result != NULL) {
        v8ConversionSlot = GitError::New(
        result,
        false
       );
   }
  else {
    v8ConversionSlot = Nan::Null();
  }
  // end convert_to_v8 block
        return info.GetReturnValue().Set(scope.Escape(v8ConversionSlot));
  }
}
       // start field block
    NAN_METHOD(GitError::Message) {
      v8::Local<v8::Value> v8ConversionSlot;

            char *
           message =
          Nan::ObjectWrap::Unwrap<GitError>(info.This())->GetValue()->message;
 // start convert_to_v8 block
  if (message){
       v8ConversionSlot = Nan::New<v8::String>(message).ToLocalChecked();
   }
  else {
    v8ConversionSlot = Nan::Null();
  }

  // end convert_to_v8 block
      info.GetReturnValue().Set(v8ConversionSlot);
    }
    // end field block
     // start field block
    NAN_METHOD(GitError::Klass) {
      v8::Local<v8::Value> v8ConversionSlot;

            int
           klass =
          Nan::ObjectWrap::Unwrap<GitError>(info.This())->GetValue()->klass;
 // start convert_to_v8 block
     v8ConversionSlot = Nan::New<Number>( klass);
  // end convert_to_v8 block
      info.GetReturnValue().Set(v8ConversionSlot);
    }
    // end field block
  // force base class template instantiation, to make sure we get all the
// methods, statics, etc.
template class NodeGitWrapper<GitErrorTraits>;
 