class ScreenService extends BasicService implements OwnerAPISupport<Screen> {

	@POST
	@Path("/claim/{key}")
	@Produces(MediaType.APPLICATION_JSON)
	public Screen claimScreen(@PathParam("key") String key, @DefaultValue("0") @QueryParam("screenId") long screenId) {
		List<Screen> onboardings = ScreenDAO.getOnboardings();
		Screen existingScreen = null;
		for (Screen screen : onboardings) {
			if (key.equalsIgnoreCase(screen.getShortKey())) {
				existingScreen = screen;
				break;
			}
		}
		if (existingScreen == null) {
			throwNotFound();
		}
		if (!existingScreen.getOwners().isEmpty()) {
			throwBadRequest("Screen is already onboarded. Contact the administrators if you think this is incorrect.");
		}

		if (screenId > 0) {
			// reuse existing screen
			Screen reuseScreen = new ScreenDAO().getById(screenId);
			if (reuseScreen == null) {
				throwNotFound();
			}
			if (!this.isAdmin() && !inAdminOwners(reuseScreen.getOwners())) {
				throwUnauthorized();
			}
			reuseScreen.setKey(existingScreen.getKey());

			// delete onboarding screen as it is not needed anymore
			new ScreenDAO().deleteById(existingScreen.getId());

			return ScreenDAO.save(reuseScreen);
		} else {
			// create new screen
			User user = userUtil.getLoggedInDBUser(request);
			Owner owner = new Owner(user);
			owner.setContact(true);
			existingScreen.addOwner(owner);
			existingScreen.setName(user.getFullName() + "'s Screen");
			return ScreenDAO.save(existingScreen);
		}
	}

}