package de.oaa.xxx.registration;

import java.util.UUID;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

@Entity
@Table(name = "registration")
public class RegistrationEntity {

	@Id
	@Column
	private UUID registrationId;
	@Column
	private String name;
	@Column
	private String email;
	@Column
	private String password;
	@Column
	private Boolean activated;

	public UUID getRegistrationId() {
		return registrationId;
	}

	public void setRegistrationId(UUID registrationId) {
		this.registrationId = registrationId;
	}

	public String getName() { 
		return name;
	}

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

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
	
	@Override
	public String toString() {
		return "RegistrationEntity [registrationId=" + registrationId + ", name=" + name + ", email=" + email + "]";
	}

	public Registration toRegistration() {
		Registration registration = new Registration();
		registration.setId(registrationId);
		registration.setEmail(email);
		registration.setName(name);
		registration.setPasswordHash(password);
		return registration;
	}
	
	public static RegistrationEntity create(Registration registration) {
		RegistrationEntity entity = new RegistrationEntity();
		entity.setRegistrationId(UUID.randomUUID());
		entity.setEmail(registration.getEmail());
		entity.setActivated(Boolean.FALSE);
		entity.setName(registration.getName());
		entity.setPassword(registration.getPasswordHash());
		return entity;
	}

	public Boolean getActivated() {
		return activated;
	}

	public void setActivated(Boolean activated) {
		this.activated = activated;
	}

	public String getPassword() {
		return password;
	}

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