package exo1.entreprise;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ouziri
 * @version 1.0
 *
 */

public final class Entreprise {
	private static Entreprise INSTANCE = new Entreprise();
	private List<IService> services;

	private Entreprise() {
		services = new ArrayList<IService>();
	}

	// Ajout d'un service
	public void addService(IService service) throws IllegalArgumentException, ServiceExistantException {
		if(this.searchServiceByName(service.getNom()) != null) {
			throw new ServiceExistantException("Service déjà existant : " + service.getNom());
		}
		this.services.add(service);
	}

	// Recherche de services par nom (clé de gestion)
	public IService searchServiceByName(String nom) {
		for (IService service : services)
			if (service.getNom().equals(nom))
				return service;
		return null;
	}
	
	public static Entreprise getInstance() {
		return INSTANCE;
	}
	
	public Entreprise reset() {
		services.clear();
		return this;
	}
}
