package fr.insa.clavardator.lib.users;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

public abstract class User {
	// Make this class observable
	private final transient PropertyChangeSupport pcs = new PropertyChangeSupport(this);
	private String username;
	private String id;

	public User() {
	}

	public User(String id) {
		this.id = id;
	}

	public User(String id, String username) {
		this.id = id;
		this.username = username;
	}

	public void addObserver(PropertyChangeListener listener) {
		pcs.addPropertyChangeListener(listener);
	}

	public void removeObserver(PropertyChangeListener listener) {
		pcs.removePropertyChangeListener(listener);
	}

	public PropertyChangeSupport getPcs() {
		return pcs;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	protected void setUsername(String newUsername) {
		pcs.firePropertyChange("username", this.username, newUsername);
		this.username = newUsername;
	}

	@Override
	public String toString() {
		return "User " + id + '(' + username + ')';
	}
}
