package src.Controller;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Utilisateur extends Object {

	private String pseudo ;
	private Integer port; 
	private InetAddress ip ; 
	private String id ; 
	
	public Utilisateur(String pseudo,Integer port, InetAddress ip ){
		this.setPseudo(pseudo) ;
		this.setPort(port);
		this.ip = ip ;
		this.id = ip.getHostName() ;
	}

	public String getPseudo() {
		return pseudo;
	}

	public void setPseudo(String pseudo) {
		this.pseudo = pseudo;
	}

	public Integer getPort() {
		return port;
	}

	public void setPort(Integer port) {
		this.port = port;
	}

	public InetAddress getIp() {
		return ip;
	}
	public String getId() {
		return id;
	}
	
	@Override
	public String toString(){
		String s = "";
		s+="pseudo " + this.pseudo + " | ";
		s+="port " + (this.port).toString() + " | ";
		s+="ip " + (this.ip).toString() + " | ";
		s+="id " + (this.id).toString() + " | ";
		return s;
	}
	
	public static Utilisateur stringToUtilisateur(String s) {
		String name = "";
		Integer port = 0;
		String ip = "" ;
		String id = "";
		String mots[] = s.split(" ");
		name=mots[1];
		port=Integer.parseInt(mots[4]);
		ip=mots[7];
		id=mots[10];
		Utilisateur user = null;
		try {
			user = new Utilisateur(name,port,InetAddress.getByName(ip.split("/")[1]));
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
		return user;
	}

	
	public Boolean equals(Utilisateur u) {
		return this.getId().equals( u.getId() ) ;
	}
	
}
