class PlaylistService extends BasicService implements OwnerAPISupport<Playlist> {

	@DELETE
	@Path("/playlists/{playlistId}")
	public Response deletePlaylist(@PathParam("playlistId") long playlistId) {
		Playlist existingPlaylist = getExistingPlaylist(playlistId, true);
		PlaylistReferences refs = getReferences(existingPlaylist.getId());
		if (refs.getForeignScreens() > 0 || !refs.getUserScreens().isEmpty()) {
			throwBadRequest("Playlist is in use in a screen.");
		}

		for (PageReference pageRef : existingPlaylist.getPageReferences()) {
			new PageReferenceDAO().deleteById(pageRef.getId());
		}
		for (Owner owner : existingPlaylist.getOwners()) {
			new OwnerDAO().deleteById(owner.getId());
		}

		return new PlaylistDAO().deleteById(playlistId) ? RESPONSE_OK : RESPONSE_BAD;
	}

}