package managedbean.profile;

import java.io.Serializable;

import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;

/**
 * ManagedBEan que gestiona la edición y actualización de una especialidad
 * médica.
 * 
 * @author mark
 *
 */
@Named("addPatientMBean")
@RequestScoped
public class AddPatientMBean extends ProfileMBeanBase implements Serializable {

	private static final long serialVersionUID = 1L;

	private String id;
	private String nif;
	private String name;
	private String surname;
	private String password;
	private String passwordRepeat;
	private String email;
	private String primaryHealthCareCenter;
	private String medicalSpecialty;

	/**
	 * Constructor. Inicializa la conexión con el EJB Remoto
	 * 
	 * @throws Exception
	 */
	public AddPatientMBean() throws Exception {
		super.initializeProfileFacadeRemote();
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getNif() {
		return nif;
	}

	public void setNif(String nif) {
		this.nif = nif;
	}

	public String getId() {
		return id;
	}

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

	public void save() {
		FacesMessage msg;
		
		try {
			
			
			msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Alta realizada", "El usuario " + name + " " + surname + " se ha registrado correctamente.");
		} catch (Exception e) {
			msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Se ha producido un error inesperado: " + e.getLocalizedMessage());
		}
		
		FacesContext.getCurrentInstance().addMessage(null, msg);
	}

	public String getPasswordRepeat() {
		return passwordRepeat;
	}

	public void setPasswordRepeat(String passwordRepeat) {
		this.passwordRepeat = passwordRepeat;
	}
}
