Telefono = Class.create();
Telefono.prototype = {
	initialize: function(id, marca, descripcion, imagen, precio) {
		this.caracteristicas = new Dictionary();
		this.planes         = new Dictionary();
		this.tecnologias    = new Dictionary();
		this.id 			= id;
		this.imagen 		= imagen;
		this.precio 		= precio;
		this.marca 			= marca;
		this.descripcion 	= descripcion;
	},
	getPrecio: function() {
		return this.precio;
	},
	getId: function() {
		return this.id;
	},
	getMarca: function() {
		return this.marca;
	},
	getDescripcion: function() {
		return this.descripcion;
	},
	getImagen: function() {
		return this.imagen;
	},
	getCaracteristicas: function() {
		return this.caracteristicas;
	},
	addCaracteristica: function(caracteristica) {
		if(caracteristica != null){
			this.caracteristicas.put(caracteristica.getId(), caracteristica);
		}
	},
	hasCaracteristica: function(id) {
		return this.caracteristicas.containsKey(id);
	},
	addPlan: function(plan) {
		this.planes.put(plan.getId(), plan);
	},
	hasPlan: function(id) {
		return this.planes.containsKey(id);
	},
	addTecnologia: function(tecnologia) {
		this.tecnologias.put(tecnologia.getId(), tecnologia);
	},
	hasTecnologia: function(id) {
		return this.tecnologias.containsKey(id);
	}
	
};

Caracteristica = Class.create();
Caracteristica.prototype = {
	initialize: function(id, descripcion) {
		this.id 			= id;
		this.descripcion	= descripcion;
	},
	getId: function() {
		return this.id;
	},
	getDescripcion: function() {
		return this.descripcion;
	}
};

Tecnologia = Class.create();
Tecnologia.prototype = {
	initialize: function(id, descripcion) {
		this.id 			= id;
		this.descripcion	= descripcion;
	},
	getId: function() {
		return this.id;
	},
	getDescripcion: function() {
		return this.descripcion;
	}
};

Plan = Class.create();
Plan.prototype = {
	initialize: function(id, descripcion) {
		this.id 			= id;
		this.descripcion	= descripcion;
	},
	getId: function() {
		return this.id;
	},
	getDescripcion: function() {
		return this.descripcion;
	}
};

Marca = Class.create();
Marca.prototype = {
	initialize: function(id, descripcion) {
		this.id 			= id;
		this.descripcion	= descripcion;
	},
	getId: function() {
		return this.id;
	},
	getDescripcion: function() {
		return this.descripcion;
	}
};

FiltroHelper = Class.create();
FiltroHelper.prototype = {
	initialize: function() {
		
	},
	filter: function(filtros, telefonos) {
		var telefonosFiltrados = telefonos;
		filtros.each(function(filtro){
			telefonosFiltrados = filtro.filter(telefonosFiltrados);
		});
		return telefonosFiltrados;
	}
};
FiltroPrecio = Class.create();
FiltroPrecio.prototype = {
	initialize: function(rangoPrecios) {
		this.rangoPrecios = rangoPrecios;
	},
	filter: function(telefonos) {
		var telefonosFiltrados = new Array();
		var tmpRango = this.rangoPrecios.split(",");
		telefonos.each(function(telefono){
			if (telefono.getPrecio() != null && telefono.getPrecio() > tmpRango[0]) {
				if (tmpRango[1] != null) {
					if (telefono.getPrecio() < tmpRango[1]) telefonosFiltrados.push(telefono);
				} else 
					telefonosFiltrados.push(telefono);
			}
		});
		return telefonosFiltrados;
	}
};
FiltroMarca = Class.create();
FiltroMarca.prototype = {
	initialize: function(marca) {
		this.marca = marca;
	},
	filter: function(telefonos) {
		var telefonosFiltrados = new Array();
		var filter = this;
		telefonos.each(function(telefono){
			if (filter.marca.getId() == telefono.getMarca().getId()) telefonosFiltrados.push(telefono);
		});
		return telefonosFiltrados;
	}
};

FiltroTecnologia = Class.create();
FiltroTecnologia.prototype = {
	initialize: function(tecnologia) {
		this.tecnologia = tecnologia;
	},
	filter: function(telefonos) {
		var telefonosFiltrados = new Array();
		var filter = this;
		telefonos.each(function(telefono){
			if (telefono.hasTecnologia(filter.tecnologia.getId())) telefonosFiltrados.push(telefono);
		});
		return telefonosFiltrados;
	}
};

FiltroPlan = Class.create();
FiltroPlan.prototype = {
	initialize: function(plan) {
		this.plan = plan;
	},
	filter: function(telefonos) {
		var telefonosFiltrados = new Array();
		var filter = this;
		telefonos.each(function(telefono){
			if (telefono.hasPlan(filter.plan.getId())) telefonosFiltrados.push(telefono);
		});
		return telefonosFiltrados;
	}
};
FiltroCaracteristicas = Class.create();
FiltroCaracteristicas.prototype = {
	initialize: function(ids) {
		this.ids = ids;
	},
	filter: function(telefonos) {
		var telefonosFiltrados = new Array();
		var caracteristicasIds = this.ids.split(",");
		telefonos.each(function(telefono){
			var tieneTodas = true;
			for(var i=0; i<caracteristicasIds.length; i++) {
				if (!telefono.hasCaracteristica(caracteristicasIds[i])) tieneTodas = false;
			}
			if (tieneTodas) telefonosFiltrados.push(telefono);
		});
		return telefonosFiltrados;
	}
};
