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

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


#include "../include/functions/copy.h"
#include "../include/macros.h"
#include "../include/blame_hunk.h"

  #include "../include/oid.h"
  #include "../include/signature.h"
 
#include <iostream>

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

  GitBlameHunk::GitBlameHunk(git_blame_hunk *raw, bool selfFreeing) {
    this->raw = raw;
    this->selfFreeing = selfFreeing;
  }

  GitBlameHunk::~GitBlameHunk() {
   }

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

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

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

         NODE_SET_PROTOTYPE_METHOD(tpl, "linesInHunk", LinesInHunk);
         NODE_SET_PROTOTYPE_METHOD(tpl, "finalCommitId", FinalCommitId);
         NODE_SET_PROTOTYPE_METHOD(tpl, "finalStartLineNumber", FinalStartLineNumber);
         NODE_SET_PROTOTYPE_METHOD(tpl, "finalSignature", FinalSignature);
         NODE_SET_PROTOTYPE_METHOD(tpl, "origCommitId", OrigCommitId);
         NODE_SET_PROTOTYPE_METHOD(tpl, "origPath", OrigPath);
         NODE_SET_PROTOTYPE_METHOD(tpl, "origStartLineNumber", OrigStartLineNumber);
         NODE_SET_PROTOTYPE_METHOD(tpl, "origSignature", OrigSignature);
  
    Local<Function> _constructor_template = tpl->GetFunction();
    NanAssignPersistent(constructor_template, _constructor_template);
    target->Set(NanNew<String>("BlameHunk"), _constructor_template);
  }

  NAN_METHOD(GitBlameHunk::JSNewFunction) {
    NanScope();

    if (args.Length() == 0 || !args[0]->IsExternal()) {
         return NanThrowError("A new GitBlameHunk cannot be instantiated.");
     }

    GitBlameHunk* object = new GitBlameHunk(static_cast<git_blame_hunk *>(Handle<External>::Cast(args[0])->Value()), args[1]->BooleanValue());
    object->Wrap(args.This());

    NanReturnValue(args.This());
  }

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

  git_blame_hunk *GitBlameHunk::GetValue() {
    return this->raw;
  }

  git_blame_hunk **GitBlameHunk::GetRefValue() {
    return &this->raw;
  }

      NAN_METHOD(GitBlameHunk::LinesInHunk) {
      NanScope();
      Handle<Value> to;

      uint16_t  lines_in_hunk =
 ObjectWrap::Unwrap<GitBlameHunk>(args.This())->GetValue()->lines_in_hunk;

// start convert_to_v8 block
     to = NanNew<Number>(lines_in_hunk);
  // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitBlameHunk::FinalCommitId) {
      NanScope();
      Handle<Value> to;

      git_oid * final_commit_id =
& ObjectWrap::Unwrap<GitBlameHunk>(args.This())->GetValue()->final_commit_id;

// start convert_to_v8 block
  
  if (final_commit_id != NULL) {
    // GitOid final_commit_id
       to = GitOid::New((void *)final_commit_id, false);
   }
  else {
    to = NanNull();
  }

 // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitBlameHunk::FinalStartLineNumber) {
      NanScope();
      Handle<Value> to;

      uint16_t  final_start_line_number =
 ObjectWrap::Unwrap<GitBlameHunk>(args.This())->GetValue()->final_start_line_number;

// start convert_to_v8 block
     to = NanNew<Number>(final_start_line_number);
  // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitBlameHunk::FinalSignature) {
      NanScope();
      Handle<Value> to;

      git_signature * * final_signature =
& ObjectWrap::Unwrap<GitBlameHunk>(args.This())->GetValue()->final_signature;

// start convert_to_v8 block
  
  if (final_signature != NULL) {
    // GitSignature final_signature
       to = GitSignature::New((void *)final_signature, false);
   }
  else {
    to = NanNull();
  }

 // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitBlameHunk::OrigCommitId) {
      NanScope();
      Handle<Value> to;

      git_oid * orig_commit_id =
& ObjectWrap::Unwrap<GitBlameHunk>(args.This())->GetValue()->orig_commit_id;

// start convert_to_v8 block
  
  if (orig_commit_id != NULL) {
    // GitOid orig_commit_id
       to = GitOid::New((void *)orig_commit_id, false);
   }
  else {
    to = NanNull();
  }

 // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitBlameHunk::OrigPath) {
      NanScope();
      Handle<Value> to;

      const char *  orig_path =
 ObjectWrap::Unwrap<GitBlameHunk>(args.This())->GetValue()->orig_path;

// start convert_to_v8 block
  if (orig_path){
       to = NanNew<String>(orig_path);
   }
  else {
    to = NanNull();
  }

  // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitBlameHunk::OrigStartLineNumber) {
      NanScope();
      Handle<Value> to;

      uint16_t  orig_start_line_number =
 ObjectWrap::Unwrap<GitBlameHunk>(args.This())->GetValue()->orig_start_line_number;

// start convert_to_v8 block
     to = NanNew<Number>(orig_start_line_number);
  // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitBlameHunk::OrigSignature) {
      NanScope();
      Handle<Value> to;

      git_signature * * orig_signature =
& ObjectWrap::Unwrap<GitBlameHunk>(args.This())->GetValue()->orig_signature;

// start convert_to_v8 block
  
  if (orig_signature != NULL) {
    // GitSignature orig_signature
       to = GitSignature::New((void *)orig_signature, false);
   }
  else {
    to = NanNull();
  }

 // end convert_to_v8 block
      NanReturnValue(to);
    }
    Persistent<Function> GitBlameHunk::constructor_template;
 