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

// generated from 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/blame_options.h"
#include "nodegit_wrapper.cc"

  #include "../include/oid.h"
 
using namespace v8;
using namespace node;
using namespace std;

 
ConfigurableGitBlameOptions::ConfigurableGitBlameOptions(nodegit::Context *nodegitContext)
  : nodegit::ConfigurableClassWrapper<GitBlameOptionsTraits>(nodegitContext)
{
     git_blame_options  wrappedValue = GIT_BLAME_OPTIONS_INIT;
    this->raw = (git_blame_options*) malloc(sizeof(git_blame_options ));
    memcpy(this->raw, &wrappedValue, sizeof(git_blame_options ));
 }

ConfigurableGitBlameOptions::~ConfigurableGitBlameOptions() {
               }

nodegit::ConfigurableClassWrapper<GitBlameOptionsTraits>::v8ConversionResult ConfigurableGitBlameOptions::fromJavascript(nodegit::Context *nodegitContext, v8::Local<v8::Value> input) {
  if (!input->IsObject()) {
    return {
      "Must pass object for ConfigurableGitBlameOptions"
    };
  }

  Nan::HandleScope scope;
  v8::Local<v8::Object> inputObj = input.As<v8::Object>();
  std::shared_ptr<ConfigurableGitBlameOptions> output(new ConfigurableGitBlameOptions(nodegitContext));

  // unpack the data into the correct fields
         {
          v8::Local<v8::Value> maybeNumber = nodegit::safeGetField(inputObj, "version");
          if (!maybeNumber.IsEmpty() && !maybeNumber->IsUndefined() && !maybeNumber->IsNull()) {
            if (!maybeNumber->IsNumber()) {
              return {
                "Must pass Int32 to version"
              };
            }

            output->raw->version = static_cast<unsigned int>(maybeNumber->Int32Value(Nan::GetCurrentContext()).FromJust());
          }
        }
           {
          v8::Local<v8::Value> maybeNumber = nodegit::safeGetField(inputObj, "flags");
          if (!maybeNumber.IsEmpty() && !maybeNumber->IsUndefined() && !maybeNumber->IsNull()) {
            if (!maybeNumber->IsNumber()) {
              return {
                "Must pass Int32 to flags"
              };
            }

            output->raw->flags = static_cast<unsigned int>(maybeNumber->Int32Value(Nan::GetCurrentContext()).FromJust());
          }
        }
           {
          v8::Local<v8::Value> maybeNumber = nodegit::safeGetField(inputObj, "minMatchCharacters");
          if (!maybeNumber.IsEmpty() && !maybeNumber->IsUndefined() && !maybeNumber->IsNull()) {
            if (!maybeNumber->IsNumber()) {
              return {
                "Must pass Int32 to minMatchCharacters"
              };
            }

            output->raw->min_match_characters = static_cast<uint16_t>(maybeNumber->Int32Value(Nan::GetCurrentContext()).FromJust());
          }
        }
            {
            v8::Local<v8::Value> maybeOid = nodegit::safeGetField(inputObj, "newestCommit");
            if (!maybeOid.IsEmpty() && !maybeOid->IsUndefined() && !maybeOid->IsNull()) {
              if (maybeOid->IsString()) {
                Nan::Utf8String oidString(maybeOid.As<v8::String>());
                if (git_oid_fromstr(&output->raw->newest_commit, *oidString) != GIT_OK) {
                  return {
                    git_error_last()->message
                  };
                }
              } else if (maybeOid->IsObject()) {
                if (git_oid_cpy(&output->raw->newest_commit, Nan::ObjectWrap::Unwrap<GitOid>(maybeOid.As<v8::Object>())->GetValue()) != GIT_OK) {
                  return {
                    git_error_last()->message
                  };
                }
              } else {
                return {
                  "Must pass String or NodeGit.Oid to newestCommit"
                };
              }
            }
          }
             {
            v8::Local<v8::Value> maybeOid = nodegit::safeGetField(inputObj, "oldestCommit");
            if (!maybeOid.IsEmpty() && !maybeOid->IsUndefined() && !maybeOid->IsNull()) {
              if (maybeOid->IsString()) {
                Nan::Utf8String oidString(maybeOid.As<v8::String>());
                if (git_oid_fromstr(&output->raw->oldest_commit, *oidString) != GIT_OK) {
                  return {
                    git_error_last()->message
                  };
                }
              } else if (maybeOid->IsObject()) {
                if (git_oid_cpy(&output->raw->oldest_commit, Nan::ObjectWrap::Unwrap<GitOid>(maybeOid.As<v8::Object>())->GetValue()) != GIT_OK) {
                  return {
                    git_error_last()->message
                  };
                }
              } else {
                return {
                  "Must pass String or NodeGit.Oid to oldestCommit"
                };
              }
            }
          }
            {
          v8::Local<v8::Value> maybeNumber = nodegit::safeGetField(inputObj, "minLine");
          if (!maybeNumber.IsEmpty() && !maybeNumber->IsUndefined() && !maybeNumber->IsNull()) {
            if (!maybeNumber->IsNumber()) {
              return {
                "Must pass Int32 to minLine"
              };
            }

            output->raw->min_line = static_cast<size_t>(maybeNumber->Int32Value(Nan::GetCurrentContext()).FromJust());
          }
        }
           {
          v8::Local<v8::Value> maybeNumber = nodegit::safeGetField(inputObj, "maxLine");
          if (!maybeNumber.IsEmpty() && !maybeNumber->IsUndefined() && !maybeNumber->IsNull()) {
            if (!maybeNumber->IsNumber()) {
              return {
                "Must pass Int32 to maxLine"
              };
            }

            output->raw->max_line = static_cast<size_t>(maybeNumber->Int32Value(Nan::GetCurrentContext()).FromJust());
          }
        }
    
  return {
    output
  };
}

               
// force base class template instantiation, to make sure we get all the
// methods, statics, etc.
template class nodegit::ConfigurableClassWrapper<GitBlameOptionsTraits>;
