// Path: osuCelebrity-model/src/main/java/me/reddev/osucelebrity/core/QueuedPlayer.java
// @Data
// @PersistenceCapable
// public class QueuedPlayer {
//   public static final int CANCELLED = -2;
//   public static final int DONE = -1;
//   public static final int SPECTATING = 0;
//   public static final int NEXT = 1;
//   public static final int QUEUED = 2;
// 
//   @PrimaryKey
//   @Persistent(valueStrategy = IdGeneratorStrategy.INCREMENT)
//   long id;
// 
//   OsuUser player;
// 
//   QueueSource queueSource;
// 
//   long queuedAt;
// 
//   long startedAt;
// 
//   long stoppingAt;
//   
//   @Column(defaultValue = "0")
//   long lastRemainingTimeUpdate;
// 
//   @Index
//   int state = 2;
//   
//   @Column(defaultValue = "0")
//   int boost = 0;
//   
//   /**
//    * Creates a new queued player object. This alone won't enqueue this player.
//    * 
//    * @param queuedPlayer the queued player's user object.
//    * @param queueSource the user interface via which this player was enqued.
//    * @param queuedAt current time.
//    */
//   public QueuedPlayer(OsuUser queuedPlayer, QueueSource queueSource, long queuedAt) {
//     super();
//     this.player = queuedPlayer;
//     this.queueSource = queueSource;
//     this.queuedAt = queuedAt;
//   }
// 
//   @Override
//   public boolean equals(Object other) {
//     if (other instanceof QueuedPlayer) {
//       QueuedPlayer otherUser = (QueuedPlayer) other;
//       return otherUser.player.getUserId() == player.getUserId();
//     }
//     return false;
//   }
// 
//   @Override
//   public int hashCode() {
//     return player != null ? player.getUserId() : 0;
//   }
// 
//   public enum QueueSource {
//     TWITCH, OSU, AUTO
//   }
//   
//   public boolean isNotify() {
//     return queueSource != QueueSource.AUTO && player.isAllowsNotifications();
//   }
// }


import lombok.RequiredArgsConstructor;
import me.reddev.osucelebrity.core.QueuedPlayer;
import me.reddev.osucelebrity.core.Spectator;
import me.reddev.osucelebrity.core.Vote;
import org.mapstruct.Mapper;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
package me.reddev.osucelebrity.core.api;




@Singleton
@Path("/votes")
@RequiredArgsConstructor(onConstructor = @__(@Inject))
public class VoteService {
  @Mapper
  public interface VoteMapper {
    public DisplayVote voteToDisplayVote(Vote vote);
  }

  private final PersistenceManagerFactory pmf;

  private final Spectator spectator;
  
  /**
   * Shows the votes for the current player.
   * @return List of unique votes for the current player
   */
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public List<DisplayVote> votes() {
    PersistenceManager pm = pmf.getPersistenceManager();
    
    try {
// Path: osuCelebrity-model/src/main/java/me/reddev/osucelebrity/core/QueuedPlayer.java
// @Data
// @PersistenceCapable
// public class QueuedPlayer {
//   public static final int CANCELLED = -2;
//   public static final int DONE = -1;
//   public static final int SPECTATING = 0;
//   public static final int NEXT = 1;
//   public static final int QUEUED = 2;
// 
//   @PrimaryKey
//   @Persistent(valueStrategy = IdGeneratorStrategy.INCREMENT)
//   long id;
// 
//   OsuUser player;
// 
//   QueueSource queueSource;
// 
//   long queuedAt;
// 
//   long startedAt;
// 
//   long stoppingAt;
//   
//   @Column(defaultValue = "0")
//   long lastRemainingTimeUpdate;
// 
//   @Index
//   int state = 2;
//   
//   @Column(defaultValue = "0")
//   int boost = 0;
//   
//   /**
//    * Creates a new queued player object. This alone won't enqueue this player.
//    * 
//    * @param queuedPlayer the queued player's user object.
//    * @param queueSource the user interface via which this player was enqued.
//    * @param queuedAt current time.
//    */
//   public QueuedPlayer(OsuUser queuedPlayer, QueueSource queueSource, long queuedAt) {
//     super();
//     this.player = queuedPlayer;
//     this.queueSource = queueSource;
//     this.queuedAt = queuedAt;
//   }
// 
//   @Override
//   public boolean equals(Object other) {
//     if (other instanceof QueuedPlayer) {
//       QueuedPlayer otherUser = (QueuedPlayer) other;
//       return otherUser.player.getUserId() == player.getUserId();
//     }
//     return false;
//   }
// 
//   @Override
//   public int hashCode() {
//     return player != null ? player.getUserId() : 0;
//   }
// 
//   public enum QueueSource {
//     TWITCH, OSU, AUTO
//   }
//   
//   public boolean isNotify() {
//     return queueSource != QueueSource.AUTO && player.isAllowsNotifications();
//   }
// }


// Path: osuCelebrity-core/src/main/java/me/reddev/osucelebrity/core/api/VoteService.java
import lombok.RequiredArgsConstructor;
import me.reddev.osucelebrity.core.QueuedPlayer;
import me.reddev.osucelebrity.core.Spectator;
import me.reddev.osucelebrity.core.Vote;
import org.mapstruct.Mapper;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

package me.reddev.osucelebrity.core.api;




@Singleton
@Path("/votes")
@RequiredArgsConstructor(onConstructor = @__(@Inject))
public class VoteService {
  @Mapper
  public interface VoteMapper {
    public DisplayVote voteToDisplayVote(Vote vote);
  }

  private final PersistenceManagerFactory pmf;

  private final Spectator spectator;
  
  /**
   * Shows the votes for the current player.
   * @return List of unique votes for the current player
   */
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public List<DisplayVote> votes() {
    PersistenceManager pm = pmf.getPersistenceManager();
    
    try {
      QueuedPlayer queued = spectator.getCurrentPlayer(pm);