
class NetworkMessage 
{
	
	constructor(network, params) 
	{	
		this.network = network;
		this.action = params.action;
		this.params = [];
		for (var key in params)
		{
			if (key == 'action') continue;
			this.params[key] = params[key];
		}		
	}

	send()
	{
		this.network.sendMessage(this);
	}

	toString()
	{
		var json = {};
		json.action = this.action;
		for (var key in this.params)
		{
			json[key] = this.params[key];
		}
		return JSON.stringify(json);
	}

	getAction()
	{
		return this.action;
	}

	getMessageID()
	{
		if (this.params['message_id'])
		{
			return this.params['message_id'];
		}
		return -1;
	}

	setMessageID(message_id)
	{
		this.params['message_id'] = message_id;
	}

	getParam(key, def)
	{
		if (this.params[key])
		{
			return this.params[key];
		}
		return def;
	}
}
