package vente;

import java.util.HashMap;
import java.util.Map;

import contacts.Client;
import contacts.Fournisseur;

public class Vente {
	private Map<String,IContact> contacts = new HashMap<>();
	public void ajouter(IContact contact) {
		contacts.put(contact.getNom(), contact);
	}
	public String debiter(String nom, double montant) {
		IContact client = null;
		if (contacts.containsKey(nom) 
				&& (client = contacts.get(nom)) instanceof Client)
			return "Debiter "+ client.getCarte()+ " de "+ montant+"€";
		else throw new IllegalArgumentException(nom + "n'est pas client");
	}
	public String payer(String nom, double montant) {
		IContact fournisseur = null;
		if (contacts.containsKey(nom) 
				&& (fournisseur= contacts.get(nom)) instanceof Fournisseur)
			return "Virer " + montant+ "€ sur "+ fournisseur.getCompte();
		else	
			throw new IllegalArgumentException(nom + "n'est pas fournisseurs");
	}
}
