#ifndef GITCOMMIT_H
#define GITCOMMIT_H

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

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

#include "../include/signature.h"
#include "../include/commit.h"
#include "../include/repository.h"
#include "../include/tree.h"
#include "../include/oid.h"


using namespace node;
using namespace v8;

class GitCommit : public ObjectWrap {
  public:

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

        git_commit *GetValue();

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

    
                  
    struct LookupBaton {
      int error_code;
      const git_error* error;
                    git_commit * commit;
                            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(Id);
                        
    static NAN_METHOD(Message);
                        
    static NAN_METHOD(Time);
                        
    static NAN_METHOD(TimeOffset);
                        
    static NAN_METHOD(Committer);
                        
    static NAN_METHOD(Author);
                        
    static NAN_METHOD(TreeId);
                        
    static NAN_METHOD(Parentcount);
                        
    static NAN_METHOD(ParentId);
                        
    struct CreateCommitBaton {
      int error_code;
      const git_error* error;
                    git_oid * id;
                            git_repository * repo;
                            const char * update_ref;
                            const git_signature * author;
                            const git_signature * committer;
                            const char * message_encoding;
                            const char * message;
                            const git_tree * tree;
                            size_t parent_count;
                            const git_commit ** parents;
                  };
    class CreateCommitWorker : public NanAsyncWorker {
      public:
        CreateCommitWorker(
            CreateCommitBaton *_baton,
            NanCallback *callback
        ) : NanAsyncWorker(callback)
          , baton(_baton) {};
        ~CreateCommitWorker() {};
        void Execute();
        void HandleOKCallback();

      private:
        CreateCommitBaton *baton;
    };
        
    static NAN_METHOD(CreateCommit);
          
        git_commit *raw;
    };

#endif
