var Event = require('./Event.js').Event;

/**
 * @class ErrorEvent
 * @extends Event
 * @requires Class
 * @requires Event
 *
 * @param {String} type
 * @param {Object} data
 * @param {Number} code
 * @param {String} message
 */
var ErrorEvent = function(type, data, code, message) {
    if(data instanceof ErrorEvent){
        data = data.toJson();
    }
    Event.call(this, type, data);
    this.code = code;
    this.message = message;
};
  

ErrorEvent.prototype = Object.create(Event.prototype);

ErrorEvent.prototype.toJson = function(){
    var tmpObj = {
        code : this.code,
        type : this.type,
        data : this.data,
        message :  this.message
    };
    return tmpObj;
}
/**
 * Displays error as html content
 * @return {String}
 */
ErrorEvent.prototype.toHtmlString = function(){
    var el = null;
    var retVal = "<pre>";
    for(el in this){
        if(this.hasOwnProperty(el) && typeof this[el]!='function' ){
            retVal+="\t" + el+': '+this[el]+"\n";
        }
    }
    retVal += "</pre>";
    return retVal;
};

exports.ErrorEvent = ErrorEvent;
