text: var Time = require('./Time.js');
  var MigratMigration = require('./MigratMigration.js');
  var EventEmitter = require('events').EventEmitter;
  var util = require('util');
  
  function key(migration) {
  	return migration.filename.toLowerCase();
  }
  
  function MigratState(state) {
  	this.state = state || {};
  };
  
  util.inherits(MigratState, EventEmitter);
  
  MigratState.prototype.serialize = function() {
  	return JSON.stringify(this.state);
  };
  
  MigratState.unserialize = function(serializedState) {
  	var state = new MigratState();
  	state.state = JSON.parse(serializedState) || {};
  	return state;
  };
  
  MigratState.prototype.add = function(migration) {
  	if (!(migration instanceof MigratMigration)) {
  		throw new Error('Migration not a MigratMigration instance');
  	}
  	this.state[key(migration)] = Time.stamp();
  	this.emit('change', this.serialize());
  };
  
  MigratState.prototype.remove = function(migration) {
  	if (!(migration instanceof MigratMigration)) {
  		throw new Error('Migration not a MigratMigration instance');
  	}
  	delete this.state[key(migration)];
  	this.emit('change', this.serialize());
  };
  
  MigratState.prototype.exists = function(migration) {
  	if (!(migration instanceof MigratMigration)) {
  		throw new Error('Migration not a MigratMigration instance');
  	}
  	return this.state.hasOwnProperty(key(migration));
  };
  
  module.exports = MigratState;