package Exercice3;

public class Adherent {
	private String nom;
	private int nbEmprunt;
	private static final int MAX_EMPRUNT = 6;
//	private int etat;
	private enum Etat_Adherent{NORMAL,QUOTAT_ATTEINT,SUSPENSION_DE_PRET};
	private Etat_Adherent etat;


//	private static final int NORMAL = 0;
//	private static final int QUOTAT_ATTEINT = 1;
//	private static final int SUSPENSION_DE_PRET = 2;
	
	public Adherent(String nom) {
		this.nom = nom;
		this.nbEmprunt = 0;
		this.etat = Etat_Adherent.NORMAL;
	}
	
	public void depasserDelaiEMprunt()
	{
		this.etat = Etat_Adherent.SUSPENSION_DE_PRET;
	}
	
	public void finirSuspension() throws AdherentException
	{
		if(this.etat == Etat_Adherent.SUSPENSION_DE_PRET)
		{
			this.etat = Etat_Adherent.NORMAL;
		}
		else
		{
			throw new AdherentException(AdherentException.PAS_SUSPENDU);
		}	
	}
	
	public void incrementer() throws AdherentException
	{
		if(this.etat==Etat_Adherent.NORMAL)
		{
			this.nbEmprunt++;
			if(!(this.nbEmprunt<this.MAX_EMPRUNT))
			{
				this.etat = Etat_Adherent.QUOTAT_ATTEINT;
			}
		}
		else
		{
			throw new AdherentException(AdherentException.EMPRUNT_NON_AUTORISE);
		}
	}
	
	public void decrementer()
	{
		this.nbEmprunt--;
		if(this.nbEmprunt<this.MAX_EMPRUNT && this.etat == Etat_Adherent.QUOTAT_ATTEINT)
		{
			this.etat = Etat_Adherent.NORMAL;
		}
	}
	
	
	
	
	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}
	public int getNbEmprunt() {
		return nbEmprunt;
	}
	public void setNbEmprunt(int nbEmprunt) {
		this.nbEmprunt = nbEmprunt;
	};
	
	
	
}
