package org.scify.memori;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.scify.memori.interfaces.Player;
import org.scify.memori.network.RequestManager;
import org.scify.memori.network.ServerOperationResponse;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

public class PlayerManager  implements Runnable {

    private RequestManager requestManager;

    private static int playerId;
    private static Player localPlayer;
    private static Player opponentPlayer;
    private static Player startingPlayer;
    public static boolean localPlayerIsInitiator = false;
    private String callIdentifier;

    public PlayerManager() {
        requestManager = new RequestManager();
    }

    public PlayerManager(String callIdentifier) {
        requestManager = new RequestManager();
        this.callIdentifier = callIdentifier;
    }


    private void markPlayerActive() {
        String url = "player/markActive";
        List<NameValuePair> urlParameters = new ArrayList<>();
        urlParameters.add(new BasicNameValuePair("player_id", String.valueOf(getPlayerId())));
        String response = requestManager.doPost(url, urlParameters);
    }

    public static void setLocalPlayer(Player localPlayer) {
        PlayerManager.localPlayer = localPlayer;
    }


    public static void setStartingPlayer(Player startingPlayer) {
        PlayerManager.startingPlayer = startingPlayer;
    }

    public static Player getStartingPlayer() {
        return localPlayerIsInitiator ? localPlayer : opponentPlayer;
    }

    public static void setOpponentPlayer(Player opponent) {
        PlayerManager.opponentPlayer = opponent;
    }

    public static Player getOpponentPlayer() {
        return opponentPlayer;
    }

    public static void setPlayerId(int playerId) {
        PlayerManager.playerId = playerId;
    }

    public static int getPlayerId() {
        return playerId;
    }

    public String register(String userName, String password) {
        String url = "player/register";
        List<NameValuePair> urlParameters = new ArrayList<>();
        urlParameters.add(new BasicNameValuePair("user_name", userName));
        urlParameters.add(new BasicNameValuePair("password", password));
        return this.requestManager.doPost(url, urlParameters);
    }

    public String login(String userName, String password) {
        String url = "player/login";
        List<NameValuePair> urlParameters = new ArrayList<>();
        urlParameters.add(new BasicNameValuePair("user_name", userName));
        urlParameters.add(new BasicNameValuePair("password", password));
        return this.requestManager.doPost(url, urlParameters);
    }

    public String getPlayerAvailability(String userName) {
        String url = "player/availability?user_name=" + userName;
        return this.requestManager.doGet(url);
    }

    public String getOnlinePlayersFromServer() {
        String url = "players/online";
        List<NameValuePair> urlParameters = new ArrayList<>();
        urlParameters.add(new BasicNameValuePair("player_id", String.valueOf(PlayerManager.getPlayerId())));
        url += "?player_id=" + PlayerManager.getPlayerId();
        return this.requestManager.doGet(url);
    }

    @Override
    public void run() {
        switch (callIdentifier) {
            case "PLAYER_ACTIVE":
                markPlayerActive();
            default:
                break;
        }
    }
}

@@ -101,32 +101,84 @@
 cNameValuePair;%0A
+import org.scify.memori.helper.MemoriConfiguration;%0A
 import org.scify
@@ -255,65 +255,8 @@
 ger;
-%0Aimport org.scify.memori.network.ServerOperationResponse;
 %0A%0Aim
@@ -307,46 +307,8 @@
 ist;
-%0Aimport java.util.concurrent.Callable;
 %0A%0Apu
@@ -552,24 +552,99 @@
 tingPlayer;%0A
+    private MemoriConfiguration configuration = new MemoriConfiguration();%0A
     public s
@@ -723,16 +723,43 @@
 ntifier;
+%0A    String gameIdentifier;
 %0A%0A    pu
@@ -824,24 +824,102 @@
 tManager();%0A
+        gameIdentifier = configuration.getProjectProperty(%22GAME_IDENTIFIER%22);%0A
     %7D%0A%0A    p
@@ -1052,24 +1052,102 @@
 Identifier;%0A
+        gameIdentifier = configuration.getProjectProperty(%22GAME_IDENTIFIER%22);%0A
     %7D%0A%0A%0A    
@@ -1568,25 +1568,24 @@
 yer;%0A    %7D%0A%0A
-%0A
     public s
@@ -2501,32 +2501,130 @@
 d%22, password));%0A
+        urlParameters.add(new BasicNameValuePair(%22game_flavor_pack_identifier%22, gameIdentifier));%0A
         return t
@@ -2976,32 +2976,130 @@
 d%22, password));%0A
+        urlParameters.add(new BasicNameValuePair(%22game_flavor_pack_identifier%22, gameIdentifier));%0A
         return t
@@ -3275,16 +3275,67 @@
 userName
+ + %22&game_flavor_pack_identifier=%22 + gameIdentifier
 ;%0A      
@@ -3700,16 +3700,67 @@
 ayerId()
+ + %22&game_flavor_pack_identifier=%22 + gameIdentifier
 ;%0A      

Include game pack identiier in calls for login, register, and player availability