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

#include "../include/diff_file.h"

#include <iostream>

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

GitDiffDelta::GitDiffDelta(git_diff_delta *raw, bool selfFreeing)
{
  this->raw = raw;
  this->selfFreeing = selfFreeing;
}

GitDiffDelta::~GitDiffDelta()
{
}

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

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

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

  NODE_SET_PROTOTYPE_METHOD(tpl, "status", Status);
  NODE_SET_PROTOTYPE_METHOD(tpl, "flags", Flags);
  NODE_SET_PROTOTYPE_METHOD(tpl, "similarity", Similarity);
  NODE_SET_PROTOTYPE_METHOD(tpl, "nfiles", Nfiles);
  NODE_SET_PROTOTYPE_METHOD(tpl, "oldFile", OldFile);
  NODE_SET_PROTOTYPE_METHOD(tpl, "newFile", NewFile);

  Local<Function> _constructor_template = tpl->GetFunction();
  NanAssignPersistent(constructor_template, _constructor_template);
  target->Set(NanNew<String>("DiffDelta"), _constructor_template);
}

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

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

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

  NanReturnValue(args.This());
}

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

git_diff_delta *GitDiffDelta::GetValue()
{
  return this->raw;
}

git_diff_delta **GitDiffDelta::GetRefValue()
{
  return &this->raw;
}

NAN_METHOD(GitDiffDelta::Status)
{
  NanScope();
  Handle<Value> to;

  git_delta_t  status =
    ObjectWrap::Unwrap<GitDiffDelta>(args.This())->GetValue()->status;

// start convert_to_v8 block
  to = NanNew<Number>(status);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffDelta::Flags)
{
  NanScope();
  Handle<Value> to;

  uint32_t  flags =
    ObjectWrap::Unwrap<GitDiffDelta>(args.This())->GetValue()->flags;

// start convert_to_v8 block
  to = NanNew<Number>(flags);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffDelta::Similarity)
{
  NanScope();
  Handle<Value> to;

  uint16_t  similarity =
    ObjectWrap::Unwrap<GitDiffDelta>(args.This())->GetValue()->similarity;

// start convert_to_v8 block
  to = NanNew<Number>(similarity);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffDelta::Nfiles)
{
  NanScope();
  Handle<Value> to;

  uint16_t  nfiles =
    ObjectWrap::Unwrap<GitDiffDelta>(args.This())->GetValue()->nfiles;

// start convert_to_v8 block
  to = NanNew<Number>(nfiles);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffDelta::OldFile)
{
  NanScope();
  Handle<Value> to;

  git_diff_file * old_file =
    & ObjectWrap::Unwrap<GitDiffDelta>(args.This())->GetValue()->old_file;

// start convert_to_v8 block

  if (old_file != NULL) {
    // GitDiffFile old_file
    to = GitDiffFile::New((void *)old_file, false);
  } else {
    to = NanNull();
  }

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

  git_diff_file * new_file =
    & ObjectWrap::Unwrap<GitDiffDelta>(args.This())->GetValue()->new_file;

// start convert_to_v8 block

  if (new_file != NULL) {
    // GitDiffFile new_file
    to = GitDiffFile::New((void *)new_file, false);
  } else {
    to = NanNull();
  }

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