class PlaylistService extends BasicService implements OwnerAPISupport<Playlist> {

	@POST
	@Path("/playlists/{playlistId}/copy")
	@Consumes(MediaType.APPLICATION_JSON)
	public Playlist copyPlaylist(@PathParam("playlistId") long playlistId, Playlist newPlaylist) {
		Playlist existingPlaylist = getExistingPlaylist(playlistId, false);

		Playlist copiedPlaylist = new Playlist(existingPlaylist);
		copiedPlaylist.setName(newPlaylist.getName());
		copiedPlaylist = createPlaylist(copiedPlaylist);

		// copy pages
		for (PageReference ref : existingPlaylist.getPageReferences()) {
			copiedPlaylist = addPage(copiedPlaylist.getId(), ref.getPage());
			updatePageReference(
					copiedPlaylist.getPageReferences().get(copiedPlaylist.getPageReferences().size() - 1).getId(), ref);
		}

		return copiedPlaylist;
	}

}