#ifndef GITBLOB_H
#define GITBLOB_H

#include <nan.h>
#include <string>

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

#include "../include/wrapper.h"
#include "node_buffer.h"
#include "../include/blob.h"
#include "../include/repository.h"
#include "../include/oid.h"


using namespace node;
using namespace v8;

class GitBlob : public ObjectWrap {
  public:

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

        git_blob *GetValue();

    static Handle<Value> New(void *raw);
    
  private:
        GitBlob(git_blob *raw);
    ~GitBlob();
    
    static NAN_METHOD(New);

    
                  
    struct LookupBaton {
      int error_code;
      const git_error* error;
                    git_blob * blob;
                            git_repository * repo;
                            const git_oid * id;
                  };
    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);
                        
    static NAN_METHOD(Rawcontent);
                        
    static NAN_METHOD(Rawsize);
                        
    struct CreateFrombufferBaton {
      int error_code;
      const git_error* error;
                    git_oid * id;
                            git_repository * repo;
                            const void * buffer;
                            size_t len;
                  };
    class CreateFrombufferWorker : public NanAsyncWorker {
      public:
        CreateFrombufferWorker(
            CreateFrombufferBaton *_baton,
            NanCallback *callback
        ) : NanAsyncWorker(callback)
          , baton(_baton) {};
        ~CreateFrombufferWorker() {};
        void Execute();
        void HandleOKCallback();

      private:
        CreateFrombufferBaton *baton;
    };
        
    static NAN_METHOD(CreateFrombuffer);
                        
    static NAN_METHOD(IsBinary);
          
        git_blob *raw;
    };

#endif
