/*
 * Creates a helloworld hook, then spawns three helloworld children
 */

var hookio = require('../../../lib/hookio');

var hook1 = hookio.createHook({ 
  name: "server-hook",
  debug: true
});

hook1.on('hello', function (data, callback) {
  //
  // callback is the callback for this event,
  // should it exist
  //
  var result = {
    "text": "Why hello there!"
  };
  
  callback(null, result);

})

hook1.on('hook::ready', function () {
  

    //
    // Event with data
    // event, data, callback
    //
    hook1.emit('hello', 'data1', function (err, data) {
      console.log('callback1 ', err, data);
    });

    //
    // Event with data
    // event, data, callback
    //
    hook1.emit('hello', {"foo":"bar"}, function (err, data) {
      console.log('callback2 ', err, data);
    });

    //
    // Event with no data
    // event, callback
    //
    hook1.emit('hello', function (err, data) {
      console.log('callback3 ', err, data);
    });

  
});

hook1.start();