/**
   * Description: Updates note for league player, only requires league_id, player_projected_id and
   * team_player_note from container.
   *
   * @param container
   * @param uname
   * @return Long, id of saved LeaguePlayer
   */
  public Long updateLeaguePlayerNote(LeaguePlayerInputNoteContainer container, String uname) {

    Key<League> leaguekey = Key.create(League.class, container.getLeague_id());
    Key<PlayerProjected> playerprojectedkey =
        Key.create(PlayerProjected.class, container.getPlayer_projected_id());

    // Check to see if LeaguePlayer already exists
    List<LeaguePlayer> leagueplayers =
        ofy()
            .load()
            .type(LeaguePlayer.class)
            .filter("league", leaguekey)
            .filter("player_projected", playerprojectedkey)
            .list();

    LeaguePlayer lp = new LeaguePlayer();

    // If exists, update existing LeaguePlayer note
    // Otherwise, update new LeaguePlayer with note
    if (leagueplayers.size() > 0) {
      lp = leagueplayers.get(0);
    } else {
      lp.setLeagueRef(Ref.create(leaguekey));
      lp.setPlayer_projected(Ref.create(playerprojectedkey));
    }

    lp.setTeam_player_note(container.getTeam_player_note());

    System.out.println("Saving player note for: " + lp.getPlayer_projected().getFull_name());
    System.out.println("Player note: " + lp.getTeam_player_note());

    return this.save(lp, uname);
  }
  /**
   * Description: Updates custom position eligibility for league player, only requires league_id,
   * player_projected_id and custom_position_eligibility from container.
   *
   * @param container
   * @param uname
   * @return Long, id of saved LeaguePlayer
   */
  public Long updateLeaguePlayerCustomPosition(
      LeaguePlayerInputCustPosContainer container, String uname) {

    Key<League> leaguekey = Key.create(League.class, container.getLeague_id());
    Key<PlayerProjected> playerprojectedkey =
        Key.create(PlayerProjected.class, container.getPlayer_projected_id());

    // Check to see if LeaguePlayer already exists
    List<LeaguePlayer> leagueplayers =
        ofy()
            .load()
            .type(LeaguePlayer.class)
            .filter("league", leaguekey)
            .filter("player_projected", playerprojectedkey)
            .list();

    LeaguePlayer lp = new LeaguePlayer();

    // If exists, update existing LeaguePlayer custom position
    // Otherwise, update new LeaguePlayer with custom position
    if (leagueplayers.size() > 0) {
      lp = leagueplayers.get(0);
    } else {
      lp.setLeagueRef(Ref.create(leaguekey));
      lp.setPlayer_projected(Ref.create(playerprojectedkey));
    }

    lp.setCustom_position(container.getCustom_position_eligibility());
    lp.setCustom_position_flag(true);

    System.out.println(
        "Saving player custom position for: " + lp.getPlayer_projected().getFull_name());
    System.out.println("Custom position: " + lp.getCustom_position());

    return this.save(lp, uname);
  }
  public long draftLeaguePlayer(LeaguePlayerInputDraftContainer container, String uname) {

    System.out.println("draftLeaguePlayer: BEGIN");

    Key<LeagueTeam> teamkey = Key.create(LeagueTeam.class, container.getLeague_team_id());
    Key<League> leaguekey = Key.create(League.class, container.getLeague_id());

    List<LeaguePlayer> leagueplayers = new ArrayList<LeaguePlayer>();

    LeaguePlayer lp = new LeaguePlayer();

    System.out.println(
        "draftLeaguePlayer: unknown_player_name: " + container.getUnknown_player_name());
    System.out.println("draftLeaguePlayer: unknownplayer: " + container.isUnknownplayer());

    if (container.isUnknownplayer()) {

      // Check to see if LeaguePlayer already exists
      leagueplayers =
          ofy()
              .load()
              .type(LeaguePlayer.class)
              .filter("league", leaguekey)
              .filter("unknown_player_name", container.getUnknown_player_name())
              .list();

      // If exists, update existing LeaguePlayer
      // Otherwise, update new LeaguePlayer with draft information
      if (leagueplayers.size() > 0) {
        System.out.println(
            "draftLeaguePlayer: found existing unknown LeaguePlayer: "
                + container.getUnknown_player_name());
        lp = leagueplayers.get(0);
      } else {
        System.out.println(
            "draftLeaguePlayer: Did NOT find existing unknown LeaguePlayer: "
                + container.getUnknown_player_name());
        lp.setLeagueRef(Ref.create(leaguekey));
      }

      lp.setUnknownplayer(true);
      lp.setUnknown_player_name(container.getUnknown_player_name());
      lp.setUnknown_player_pitcher_hitter(container.getUnknown_player_pitcher_hitter());
      System.out.println(
          "draftLeaguePlayer: Set unknown player name: " + lp.getUnknown_player_name());

      lp.setLeague_team(Ref.create(teamkey));
      lp.setTeam_player_salary(container.getTeam_player_salary());
      lp.setTeam_roster_position(container.getTeam_roster_position());

      System.out.println("draftLeaguePlayer: Right before save 1: " + lp.getUnknown_player_name());

      return this.save(lp, uname);

    } else {
      System.out.println("draftLeaguePlayer: IN ELSE STATEMENT");
      Key<PlayerProjected> playerprojectedkey =
          Key.create(PlayerProjected.class, container.getPlayer_projected_id());

      // Check to see if LeaguePlayer already exists
      leagueplayers =
          ofy()
              .load()
              .type(LeaguePlayer.class)
              .filter("league", leaguekey)
              .filter("player_projected", playerprojectedkey)
              .list();

      // If exists, update existing LeaguePlayer
      // Otherwise, update new LeaguePlayer with draft information
      if (leagueplayers.size() > 0) {
        lp = leagueplayers.get(0);
      } else {
        lp.setLeagueRef(Ref.create(leaguekey));
        lp.setPlayer_projected(Ref.create(playerprojectedkey));
      }
    }

    lp.setLeague_team(Ref.create(teamkey));
    lp.setTeam_player_salary(container.getTeam_player_salary());
    lp.setTeam_roster_position(container.getTeam_roster_position());

    System.out.println("draftLeaguePlayer: Right before save 2: " + lp.getUnknown_player_name());

    return this.save(lp, uname);
  }