#ifndef GITBLOB_H
#define GITBLOB_H
// generated from class_header.h
#include <nan.h>
#include <string>

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

#include "../include/wrapper.h"
#include "node_buffer.h"
#include "../include/oid.h"
#include "../include/repository.h"
#include "../include/blob.h"
// Forward declaration.
struct git_blob {
};

using namespace node;
using namespace v8;

class GitBlob : public ObjectWrap {
  public:

    static Persistent<Function> constructor_template;
    static void InitializeComponent (Handle<v8::Object> target);

    git_blob *GetValue();
    git_blob **GetRefValue();

    static Handle<Value> New(void *raw, bool selfFreeing);
    bool selfFreeing;

  private:
    GitBlob(git_blob *raw, bool selfFreeing);
    ~GitBlob();

    static NAN_METHOD(JSNewFunction);


    static NAN_METHOD(CreateFrombuffer);

    static NAN_METHOD(CreateFromdisk);

    static NAN_METHOD(CreateFromworkdir);

    static NAN_METHOD(Id);

    static NAN_METHOD(IsBinary);

    struct LookupBaton {
      int error_code;
      const git_error* error;
      git_blob * blob;
      git_repository * repo;
      const git_oid * id;
      bool idNeedsFree;
    };
    class LookupWorker : public NanAsyncWorker {
      public:
        LookupWorker(
            LookupBaton *_baton,
            NanCallback *callback
        ) : NanAsyncWorker(callback)
          , baton(_baton) {};
        ~LookupWorker() {};
        void Execute();
        void HandleOKCallback();

      private:
        LookupBaton *baton;
    };

    static NAN_METHOD(Lookup);

    struct LookupPrefixBaton {
      int error_code;
      const git_error* error;
      git_blob * blob;
      git_repository * repo;
      const git_oid * id;
      bool idNeedsFree;
      size_t len;
    };
    class LookupPrefixWorker : public NanAsyncWorker {
      public:
        LookupPrefixWorker(
            LookupPrefixBaton *_baton,
            NanCallback *callback
        ) : NanAsyncWorker(callback)
          , baton(_baton) {};
        ~LookupPrefixWorker() {};
        void Execute();
        void HandleOKCallback();

      private:
        LookupPrefixBaton *baton;
    };

    static NAN_METHOD(LookupPrefix);

    static NAN_METHOD(Owner);

    static NAN_METHOD(Rawcontent);

    static NAN_METHOD(Rawsize);
    git_blob *raw;
};

#endif
