package Bibliothèque;

import java.util.Arrays;
import java.util.Collection;
import java.util.Vector;

public class Auteur implements Cloneable {
	
	private String nom;
	private String prenom;
	private int age;
	private Vector<Livre> mesLivres;
	
	public Auteur(String nom, String prenom, int age) {
		this.nom = nom;
		this.prenom = prenom;
		this.age = age;
		this.mesLivres = new Vector<Livre>();
	}

	public Auteur(String nom, String prenom, int age , Livre...livres ) {
		this.nom = nom;
		this.prenom = prenom;
		this.age = age;
		this.mesLivres = new Vector<Livre>();
		this.mesLivres.addAll(Arrays.asList(livres));
	}
	
	public boolean ajouterLivre(Livre l)
	{
		if(!livrePresent(l))
		{
			this.mesLivres.add(l);
			return true;
		}
		return false;
	}
	
	public boolean supprimerLivre(Livre l)
	{
		if(livrePresent(l))
		{
			this.mesLivres.remove(l);
			return true;
		}
		return false;
	}
	
	private boolean livrePresent(Livre l) {
		for(Livre current : mesLivres)
		{
			if(l.equals(current))
			{	
				return true;
			}
		}
		return false;
	}

	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	public String getPrenom() {
		return prenom;
	}

	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public Vector<Livre> getMesLivres() {
		return mesLivres;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Auteur other = (Auteur) obj;
		if (age != other.age)
			return false;
		if (nom == null) {
			if (other.nom != null)
				return false;
		} else if (!nom.equals(other.nom))
			return false;
		if (prenom == null) {
			if (other.prenom != null)
				return false;
		} else if (!prenom.equals(other.prenom))
			return false;
		return true;
	}
		
	
}
