package de.oaa.xxx.user;

import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;

@ApplicationScoped
@Path("user")
public class UserResource {
	
	@Inject private UserDAO dao;
	
	private static final Logger LOGGER = LoggerFactory.getLogger(UserResource.class);
	
	@POST
	public Response userAnlegen(Registration registration) {
		try {
			UserEntity entity = new UserEntity();
			entity.setUserId(UUID.randomUUID());
			entity.setEmail(registration.getEmail());
			entity.setName(registration.getName());
			entity.setPassword(registration.getPasswordHash());
			dao.persist(entity);
			return Response.ok().build();
		} catch (Exception exception) {
			LOGGER.error(exception.getMessage(), exception);
			return Response.serverError().build();
		}

	}
}
