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

  #include "../include/diff_file.h"
  #include "../include/strarray.h"
  #include "../include/tree.h"
  #include "../include/index.h"
  #include "../include/checkout_perfdata.h"
 
using namespace v8;
using namespace node;
using namespace std;

 
ConfigurableGitCheckoutOptions::ConfigurableGitCheckoutOptions(nodegit::Context *nodegitContext)
  : nodegit::ConfigurableClassWrapper<GitCheckoutOptionsTraits>(nodegitContext)
{
     git_checkout_options  wrappedValue = GIT_CHECKOUT_OPTIONS_INIT;
    this->raw = (git_checkout_options*) malloc(sizeof(git_checkout_options ));
    memcpy(this->raw, &wrappedValue, sizeof(git_checkout_options ));
 }

ConfigurableGitCheckoutOptions::~ConfigurableGitCheckoutOptions() {
                              if (this->raw->paths.count) {
          for (size_t i = 0; i < this->raw->paths.count; ++i) {
            delete this->raw->paths.strings[i];
          }
          delete[] this->raw->paths.strings;
        }
              delete this->raw->target_directory;
          delete this->raw->ancestor_label;
          delete this->raw->our_label;
          delete this->raw->their_label;
       }

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

  Nan::HandleScope scope;
  v8::Local<v8::Object> inputObj = input.As<v8::Object>();
  std::shared_ptr<ConfigurableGitCheckoutOptions> output(new ConfigurableGitCheckoutOptions(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, "checkoutStrategy");
          if (!maybeNumber.IsEmpty() && !maybeNumber->IsUndefined() && !maybeNumber->IsNull()) {
            if (!maybeNumber->IsNumber()) {
              return {
                "Must pass Int32 to checkoutStrategy"
              };
            }

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

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

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

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

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

            output->raw->notify_flags = static_cast<unsigned int>(maybeNumber->Int32Value(Nan::GetCurrentContext()).FromJust());
          }
        }
          {
          v8::Local<v8::Value> maybeCallback = nodegit::safeGetField(inputObj, "notifyCb");
          if (!maybeCallback.IsEmpty() && !maybeCallback->IsUndefined() && !maybeCallback->IsNull()) {
            if (!maybeCallback->IsFunction() && !maybeCallback->IsObject()) {
              return {
                "Must pass Function or CallbackSpecifier to notifyCb"
              };
            }

            std::unique_ptr<Nan::Callback> callback;
            uint32_t throttle =  0 ;
            bool waitForResult = true;

            if (maybeCallback->IsFunction()) {
              callback.reset(new Nan::Callback(maybeCallback.As<v8::Function>()));
            } else {
              v8::Local<v8::Object> callbackSpecifier = maybeCallback.As<v8::Object>();
              v8::Local<v8::Value> maybeCallback = nodegit::safeGetField(callbackSpecifier, "callback");
              if (maybeCallback.IsEmpty() || !maybeCallback->IsFunction()) {
                return {
                  "Must pass callback to CallbackSpecifier"
                };
              }

              callback.reset(new Nan::Callback(maybeCallback.As<v8::Function>()));

              v8::Local<v8::Value> maybeThrottle = nodegit::safeGetField(callbackSpecifier, "throttle");
              if (!maybeThrottle.IsEmpty() && !maybeThrottle->IsUndefined() && !maybeThrottle->IsNull()) {
                if (!maybeThrottle->IsNumber()) {
                  return {
                    "Must pass zero or positive number as throttle to CallbackSpecifier"
                  };
                }

                throttle = maybeThrottle->Uint32Value(Nan::GetCurrentContext()).FromJust();
              }

              v8::Local<v8::Value> maybeWaitForResult = nodegit::safeGetField(callbackSpecifier, "waitForResult");
              if (!maybeWaitForResult.IsEmpty() && !maybeWaitForResult->IsUndefined() && !maybeWaitForResult->IsNull()) {
                if (!maybeWaitForResult->IsBoolean()) {
                  return {
                    "Must pass a boolean as waitForResult to callbackSpecifier"
                  };
                }

                waitForResult = Nan::To<bool>(maybeWaitForResult).FromJust();
              }
            }

            output->notifyCb.SetCallback(std::move(callback), throttle, waitForResult);
            output->raw->notify_cb = (git_checkout_notify_cb)notifyCb_cppCallback;
          }
        }
          output->raw->notify_payload = (void *)output.get();
          {
          v8::Local<v8::Value> maybeCallback = nodegit::safeGetField(inputObj, "progressCb");
          if (!maybeCallback.IsEmpty() && !maybeCallback->IsUndefined() && !maybeCallback->IsNull()) {
            if (!maybeCallback->IsFunction() && !maybeCallback->IsObject()) {
              return {
                "Must pass Function or CallbackSpecifier to progressCb"
              };
            }

            std::unique_ptr<Nan::Callback> callback;
            uint32_t throttle = 100 ;
            bool waitForResult = true;

            if (maybeCallback->IsFunction()) {
              callback.reset(new Nan::Callback(maybeCallback.As<v8::Function>()));
            } else {
              v8::Local<v8::Object> callbackSpecifier = maybeCallback.As<v8::Object>();
              v8::Local<v8::Value> maybeCallback = nodegit::safeGetField(callbackSpecifier, "callback");
              if (maybeCallback.IsEmpty() || !maybeCallback->IsFunction()) {
                return {
                  "Must pass callback to CallbackSpecifier"
                };
              }

              callback.reset(new Nan::Callback(maybeCallback.As<v8::Function>()));

              v8::Local<v8::Value> maybeThrottle = nodegit::safeGetField(callbackSpecifier, "throttle");
              if (!maybeThrottle.IsEmpty() && !maybeThrottle->IsUndefined() && !maybeThrottle->IsNull()) {
                if (!maybeThrottle->IsNumber()) {
                  return {
                    "Must pass zero or positive number as throttle to CallbackSpecifier"
                  };
                }

                throttle = maybeThrottle->Uint32Value(Nan::GetCurrentContext()).FromJust();
              }

              v8::Local<v8::Value> maybeWaitForResult = nodegit::safeGetField(callbackSpecifier, "waitForResult");
              if (!maybeWaitForResult.IsEmpty() && !maybeWaitForResult->IsUndefined() && !maybeWaitForResult->IsNull()) {
                if (!maybeWaitForResult->IsBoolean()) {
                  return {
                    "Must pass a boolean as waitForResult to callbackSpecifier"
                  };
                }

                waitForResult = Nan::To<bool>(maybeWaitForResult).FromJust();
              }
            }

            output->progressCb.SetCallback(std::move(callback), throttle, waitForResult);
            output->raw->progress_cb = (git_checkout_progress_cb)progressCb_cppCallback;
          }
        }
          output->raw->progress_payload = (void *)output.get();
            output->raw->paths.count = 0;
          output->raw->paths.strings = nullptr;

          {
            v8::Local<v8::Value> maybeStrarray = nodegit::safeGetField(inputObj, "paths");
            if (!maybeStrarray.IsEmpty() && !maybeStrarray->IsUndefined() && !maybeStrarray->IsNull()) {
              if (maybeStrarray->IsArray()) {
                v8::Local<v8::Array> strarrayValue = maybeStrarray.As<v8::Array>();
                // validate the StrArray is indeed a list of strings
                for (uint32_t i = 0; i < strarrayValue->Length(); ++i) {
                  // TODO confirm that sparse array at least boils down to undefined
                  v8::Local<v8::Value> arrayValue = Nan::Get(strarrayValue, i).ToLocalChecked();
                  if (!arrayValue->IsString()) {
                    return {
                      "Must pass String or Array of strings to paths"
                    };
                  }
                }

                StrArrayConverter::ConvertInto(&output->raw->paths, strarrayValue);
              } else if (maybeStrarray->IsString()) {
                v8::Local<v8::String> strarrayValue = maybeStrarray.As<v8::String>();
                StrArrayConverter::ConvertInto(&output->raw->paths, strarrayValue);
              } else {
                return {
                  "Must pass String or Array of strings to paths"
                };
              }
            }
          }
              {
            v8::Local<v8::Value> maybeObject = nodegit::safeGetField(inputObj, "baseline");
            if (!maybeObject.IsEmpty() && !maybeObject->IsUndefined() && !maybeObject->IsNull()) {
              if (!maybeObject->IsObject()) {
                return {
                  "Must pass NodeGit.Tree to baseline"
                };
              }

              v8::Local<v8::Object> objectValue = maybeObject.As<v8::Object>();
              output->raw->baseline = Nan::ObjectWrap::Unwrap<GitTree>(objectValue)->GetValue();
              output->baseline.Reset(objectValue);
            }
          }
              {
            v8::Local<v8::Value> maybeObject = nodegit::safeGetField(inputObj, "baselineIndex");
            if (!maybeObject.IsEmpty() && !maybeObject->IsUndefined() && !maybeObject->IsNull()) {
              if (!maybeObject->IsObject()) {
                return {
                  "Must pass NodeGit.Index to baselineIndex"
                };
              }

              v8::Local<v8::Object> objectValue = maybeObject.As<v8::Object>();
              output->raw->baseline_index = Nan::ObjectWrap::Unwrap<GitIndex>(objectValue)->GetValue();
              output->baselineIndex.Reset(objectValue);
            }
          }
           output->raw->target_directory = nullptr;
        {
          v8::Local<v8::Value> maybeString = nodegit::safeGetField(inputObj, "targetDirectory");
          if (!maybeString.IsEmpty() && !maybeString->IsUndefined() && !maybeString->IsNull()) {
            if (!maybeString->IsString()) {
              return {
                "Must pass string to targetDirectory"
              };
            }

            Nan::Utf8String utf8String(maybeString.As<v8::String>());
            output->raw->target_directory = strdup(*utf8String);
          }
        }
          output->raw->ancestor_label = nullptr;
        {
          v8::Local<v8::Value> maybeString = nodegit::safeGetField(inputObj, "ancestorLabel");
          if (!maybeString.IsEmpty() && !maybeString->IsUndefined() && !maybeString->IsNull()) {
            if (!maybeString->IsString()) {
              return {
                "Must pass string to ancestorLabel"
              };
            }

            Nan::Utf8String utf8String(maybeString.As<v8::String>());
            output->raw->ancestor_label = strdup(*utf8String);
          }
        }
          output->raw->our_label = nullptr;
        {
          v8::Local<v8::Value> maybeString = nodegit::safeGetField(inputObj, "ourLabel");
          if (!maybeString.IsEmpty() && !maybeString->IsUndefined() && !maybeString->IsNull()) {
            if (!maybeString->IsString()) {
              return {
                "Must pass string to ourLabel"
              };
            }

            Nan::Utf8String utf8String(maybeString.As<v8::String>());
            output->raw->our_label = strdup(*utf8String);
          }
        }
          output->raw->their_label = nullptr;
        {
          v8::Local<v8::Value> maybeString = nodegit::safeGetField(inputObj, "theirLabel");
          if (!maybeString.IsEmpty() && !maybeString->IsUndefined() && !maybeString->IsNull()) {
            if (!maybeString->IsString()) {
              return {
                "Must pass string to theirLabel"
              };
            }

            Nan::Utf8String utf8String(maybeString.As<v8::String>());
            output->raw->their_label = strdup(*utf8String);
          }
        }
          {
          v8::Local<v8::Value> maybeCallback = nodegit::safeGetField(inputObj, "perfdataCb");
          if (!maybeCallback.IsEmpty() && !maybeCallback->IsUndefined() && !maybeCallback->IsNull()) {
            if (!maybeCallback->IsFunction() && !maybeCallback->IsObject()) {
              return {
                "Must pass Function or CallbackSpecifier to perfdataCb"
              };
            }

            std::unique_ptr<Nan::Callback> callback;
            uint32_t throttle = 100 ;
            bool waitForResult = true;

            if (maybeCallback->IsFunction()) {
              callback.reset(new Nan::Callback(maybeCallback.As<v8::Function>()));
            } else {
              v8::Local<v8::Object> callbackSpecifier = maybeCallback.As<v8::Object>();
              v8::Local<v8::Value> maybeCallback = nodegit::safeGetField(callbackSpecifier, "callback");
              if (maybeCallback.IsEmpty() || !maybeCallback->IsFunction()) {
                return {
                  "Must pass callback to CallbackSpecifier"
                };
              }

              callback.reset(new Nan::Callback(maybeCallback.As<v8::Function>()));

              v8::Local<v8::Value> maybeThrottle = nodegit::safeGetField(callbackSpecifier, "throttle");
              if (!maybeThrottle.IsEmpty() && !maybeThrottle->IsUndefined() && !maybeThrottle->IsNull()) {
                if (!maybeThrottle->IsNumber()) {
                  return {
                    "Must pass zero or positive number as throttle to CallbackSpecifier"
                  };
                }

                throttle = maybeThrottle->Uint32Value(Nan::GetCurrentContext()).FromJust();
              }

              v8::Local<v8::Value> maybeWaitForResult = nodegit::safeGetField(callbackSpecifier, "waitForResult");
              if (!maybeWaitForResult.IsEmpty() && !maybeWaitForResult->IsUndefined() && !maybeWaitForResult->IsNull()) {
                if (!maybeWaitForResult->IsBoolean()) {
                  return {
                    "Must pass a boolean as waitForResult to callbackSpecifier"
                  };
                }

                waitForResult = Nan::To<bool>(maybeWaitForResult).FromJust();
              }
            }

            output->perfdataCb.SetCallback(std::move(callback), throttle, waitForResult);
            output->raw->perfdata_cb = (git_checkout_perfdata_cb)perfdataCb_cppCallback;
          }
        }
          output->raw->perfdata_payload = (void *)output.get();
    
  return {
    output
  };
}

                    ConfigurableGitCheckoutOptions* ConfigurableGitCheckoutOptions::notifyCb_getInstanceFromBaton(NotifyCbBaton* baton) {
           return static_cast<ConfigurableGitCheckoutOptions*>(baton->
                   payload
  );
       }

      int ConfigurableGitCheckoutOptions::notifyCb_cppCallback (
          git_checkout_notify_t why,           const char * path,           const git_diff_file * baseline,           const git_diff_file * target,           const git_diff_file * workdir,           void * payload        ) {
        NotifyCbBaton *baton =
          new NotifyCbBaton(1);

          baton->why = why;
          baton->path = path;
          baton->baseline = baseline;
          baton->target = target;
          baton->workdir = workdir;
          baton->payload = payload;
 
        ConfigurableGitCheckoutOptions* instance = notifyCb_getInstanceFromBaton(baton);

           int result;

          if (instance->nodegitContext != nodegit::ThreadPool::GetCurrentContext()) {
            result = baton->defaultResult;
            delete baton;
          } else if (instance->notifyCb.WillBeThrottled()) {
            result = baton->defaultResult;
            delete baton;
          } else if (instance->notifyCb.ShouldWaitForResult()) {
            result = baton->ExecuteAsync(notifyCb_async, notifyCb_cancelAsync);
            delete baton;
          } else {
            result = baton->defaultResult;
            baton->ExecuteAsync(notifyCb_async, notifyCb_cancelAsync, nodegit::deleteBaton);
          }
          return result;
       }

      void ConfigurableGitCheckoutOptions::notifyCb_cancelAsync(void *untypedBaton) {
        NotifyCbBaton* baton = static_cast<NotifyCbBaton*>(untypedBaton);
          baton->result = 0;
         baton->Done();
      }

      void ConfigurableGitCheckoutOptions::notifyCb_async(void *untypedBaton) {
        Nan::HandleScope scope;

        NotifyCbBaton* baton = static_cast<NotifyCbBaton*>(untypedBaton);
        ConfigurableGitCheckoutOptions* instance = notifyCb_getInstanceFromBaton(baton);

        if (instance->notifyCb.GetCallback()->IsEmpty()) {
            baton->result = baton->defaultResult; // no results acquired
           baton->Done();
          return;
        }

                 v8::Local<v8::Value> argv[5] = {
               Nan::New((int)baton->why)
 ,               baton->path == NULL
                ? Nan::EmptyString()
                : Nan::New( baton->path).ToLocalChecked()
 ,               GitDiffFile::New(baton->baseline, false)
 ,               GitDiffFile::New(baton->target, false)
 ,               GitDiffFile::New(baton->workdir, false)
            };
 
        Nan::TryCatch tryCatch;

        Nan::MaybeLocal<v8::Value> maybeResult = (*(instance->notifyCb.GetCallback()))(
          baton->GetAsyncResource(),
          5,
          argv
        );
        v8::Local<v8::Value> result;
        if (!maybeResult.IsEmpty()) {
          result = maybeResult.ToLocalChecked();
        }

        if (PromiseCompletion::ForwardIfPromise(result, baton, ConfigurableGitCheckoutOptions::notifyCb_promiseCompleted)) {
          return;
        }

             if (result.IsEmpty() || result->IsNativeError()) {
              baton->result = -1;
            }
            else if (!result->IsNull() && !result->IsUndefined()) {
                 if (result->IsNumber()) {
                  baton->result = Nan::To<int>(result).FromJust();
                }
                else {
                  baton->result = baton->defaultResult;
                }
             }
            else {
              baton->result = baton->defaultResult;
            }
           baton->Done();
       }

      void ConfigurableGitCheckoutOptions::notifyCb_promiseCompleted(bool isFulfilled, nodegit::AsyncBaton *_baton, v8::Local<v8::Value> result) {
        Nan::HandleScope scope;

        NotifyCbBaton* baton = static_cast<NotifyCbBaton*>(_baton);
           if (isFulfilled) {
              if (result.IsEmpty() || result->IsNativeError()) {
                baton->result = -1;
              }
              else if (!result->IsNull() && !result->IsUndefined()) {
                   if (result->IsNumber()) {
                    baton->result = Nan::To<int>(result).FromJust();
                  }
                  else {
                    baton->result = baton->defaultResult;
                  }
               }
              else {
                baton->result = baton->defaultResult;
              }
           }
          else {
            // promise was rejected
               ConfigurableGitCheckoutOptions* instance = static_cast<ConfigurableGitCheckoutOptions*>(baton->     payload  );
             baton->SetCallbackError(result);
            baton->result = -1;
          }
          baton->Done();
       }
          ConfigurableGitCheckoutOptions* ConfigurableGitCheckoutOptions::progressCb_getInstanceFromBaton(ProgressCbBaton* baton) {
           return static_cast<ConfigurableGitCheckoutOptions*>(baton->
                 payload
  );
       }

      void ConfigurableGitCheckoutOptions::progressCb_cppCallback (
          const char * path,           size_t completed_steps,           size_t total_steps,           void * payload        ) {
        ProgressCbBaton *baton =
          new ProgressCbBaton();

          baton->path = path;
          baton->completed_steps = completed_steps;
          baton->total_steps = total_steps;
          baton->payload = payload;
 
        ConfigurableGitCheckoutOptions* instance = progressCb_getInstanceFromBaton(baton);

          if (instance->nodegitContext != nodegit::ThreadPool::GetCurrentContext()) {
            delete baton;
          } else if (instance->progressCb.WillBeThrottled()) {
            delete baton;
          } else if (instance->progressCb.ShouldWaitForResult()) {
            baton->ExecuteAsync(progressCb_async, progressCb_cancelAsync);
            delete baton;
          } else {
            baton->ExecuteAsync(progressCb_async, progressCb_cancelAsync, nodegit::deleteBaton);
          }
          return;
       }

      void ConfigurableGitCheckoutOptions::progressCb_cancelAsync(void *untypedBaton) {
        ProgressCbBaton* baton = static_cast<ProgressCbBaton*>(untypedBaton);
         baton->Done();
      }

      void ConfigurableGitCheckoutOptions::progressCb_async(void *untypedBaton) {
        Nan::HandleScope scope;

        ProgressCbBaton* baton = static_cast<ProgressCbBaton*>(untypedBaton);
        ConfigurableGitCheckoutOptions* instance = progressCb_getInstanceFromBaton(baton);

        if (instance->progressCb.GetCallback()->IsEmpty()) {
           baton->Done();
          return;
        }

               v8::Local<v8::Value> argv[3] = {
               baton->path == NULL
                ? Nan::EmptyString()
                : Nan::New( baton->path).ToLocalChecked()
 ,               // HACK: NAN should really have an overload for Nan::New to support size_t
              Nan::New((unsigned int)baton->completed_steps)
 ,               // HACK: NAN should really have an overload for Nan::New to support size_t
              Nan::New((unsigned int)baton->total_steps)
            };
 
        Nan::TryCatch tryCatch;

        Nan::MaybeLocal<v8::Value> maybeResult = (*(instance->progressCb.GetCallback()))(
          baton->GetAsyncResource(),
          3,
          argv
        );
        v8::Local<v8::Value> result;
        if (!maybeResult.IsEmpty()) {
          result = maybeResult.ToLocalChecked();
        }

        if (PromiseCompletion::ForwardIfPromise(result, baton, ConfigurableGitCheckoutOptions::progressCb_promiseCompleted)) {
          return;
        }

          baton->Done();
       }

      void ConfigurableGitCheckoutOptions::progressCb_promiseCompleted(bool isFulfilled, nodegit::AsyncBaton *_baton, v8::Local<v8::Value> result) {
        Nan::HandleScope scope;

        ProgressCbBaton* baton = static_cast<ProgressCbBaton*>(_baton);
          baton->Done();
       }
                        ConfigurableGitCheckoutOptions* ConfigurableGitCheckoutOptions::perfdataCb_getInstanceFromBaton(PerfdataCbBaton* baton) {
           return static_cast<ConfigurableGitCheckoutOptions*>(baton->
               payload
  );
       }

      void ConfigurableGitCheckoutOptions::perfdataCb_cppCallback (
          const git_checkout_perfdata * perfdata,           void * payload        ) {
        PerfdataCbBaton *baton =
          new PerfdataCbBaton();

          baton->perfdata = perfdata;
          baton->payload = payload;
 
        ConfigurableGitCheckoutOptions* instance = perfdataCb_getInstanceFromBaton(baton);

          if (instance->nodegitContext != nodegit::ThreadPool::GetCurrentContext()) {
            delete baton;
          } else if (instance->perfdataCb.WillBeThrottled()) {
            delete baton;
          } else if (instance->perfdataCb.ShouldWaitForResult()) {
            baton->ExecuteAsync(perfdataCb_async, perfdataCb_cancelAsync);
            delete baton;
          } else {
            baton->ExecuteAsync(perfdataCb_async, perfdataCb_cancelAsync, nodegit::deleteBaton);
          }
          return;
       }

      void ConfigurableGitCheckoutOptions::perfdataCb_cancelAsync(void *untypedBaton) {
        PerfdataCbBaton* baton = static_cast<PerfdataCbBaton*>(untypedBaton);
         baton->Done();
      }

      void ConfigurableGitCheckoutOptions::perfdataCb_async(void *untypedBaton) {
        Nan::HandleScope scope;

        PerfdataCbBaton* baton = static_cast<PerfdataCbBaton*>(untypedBaton);
        ConfigurableGitCheckoutOptions* instance = perfdataCb_getInstanceFromBaton(baton);

        if (instance->perfdataCb.GetCallback()->IsEmpty()) {
           baton->Done();
          return;
        }

             v8::Local<v8::Value> argv[1] = {
               GitCheckoutPerfdata::New(baton->perfdata, false)
            };
 
        Nan::TryCatch tryCatch;

        Nan::MaybeLocal<v8::Value> maybeResult = (*(instance->perfdataCb.GetCallback()))(
          baton->GetAsyncResource(),
          1,
          argv
        );
        v8::Local<v8::Value> result;
        if (!maybeResult.IsEmpty()) {
          result = maybeResult.ToLocalChecked();
        }

        if (PromiseCompletion::ForwardIfPromise(result, baton, ConfigurableGitCheckoutOptions::perfdataCb_promiseCompleted)) {
          return;
        }

          baton->Done();
       }

      void ConfigurableGitCheckoutOptions::perfdataCb_promiseCompleted(bool isFulfilled, nodegit::AsyncBaton *_baton, v8::Local<v8::Value> result) {
        Nan::HandleScope scope;

        PerfdataCbBaton* baton = static_cast<PerfdataCbBaton*>(_baton);
          baton->Done();
       }
     
// force base class template instantiation, to make sure we get all the
// methods, statics, etc.
template class nodegit::ConfigurableClassWrapper<GitCheckoutOptionsTraits>;
