package legion.muyue.best2048.data;

import com.google.gson.annotations.SerializedName;

public class GameStateResponse {
    @SerializedName("gameId")
    private String gameId;
    @SerializedName("board")
    private int[][] board; // Plateau de jeu actuel
    @SerializedName("player1Score")
    private int player1Score;
    @SerializedName("player2Score")
    private int player2Score;
    @SerializedName("currentPlayerId") // ID du joueur dont c'est le tour
    private String currentPlayerId;
    @SerializedName("isGameOver")
    private boolean isGameOver;
    @SerializedName("winnerId") // ID du gagnant si terminé, null sinon
    private String winnerId;
    @SerializedName("status")
    private String status;
    @SerializedName("player1Id") // Ajoute ce champ s'il manque
    private String player1Id;
    @SerializedName("player2Id") // Ajoute ce champ s'il manque
    private String player2Id;
    @SerializedName("targetScore") // Ajoute ce champ
    private int targetScore;

    // --- Getters ---
    public String getGameId() { return gameId; }
    public int[][] getBoard() { return board; }
    public int getPlayer1Score() { return player1Score; }
    public int getPlayer2Score() { return player2Score; }
    public String getCurrentPlayerId() { return currentPlayerId; }
    public boolean isGameOver() { return isGameOver; }
    public String getWinnerId() { return winnerId; }
    public String getStatus() { return status; }
    public String getPlayer1Id() { return player1Id; }
    public String getPlayer2Id() { return player2Id; }
    public int getTargetScore() { return targetScore; }

    // --- Méthode utilitaire pour obtenir le score de l'adversaire ---
    public int getOpponentScore(String myActualPlayerId) {
        if (myActualPlayerId == null) return 0;
        if (myActualPlayerId.equals(player1Id)) {
            // Si je suis P1, le score de l'adversaire est P2
            return player2Score;
        } else if (myActualPlayerId.equals(player2Id)) {
            // Si je suis P2, le score de l'adversaire est P1
            return player1Score;
        }
        return 0; // Mon ID ne correspond à aucun joueur ?
    }

    public int getMyScore(String myActualPlayerId) {
        if (myActualPlayerId == null) return 0;
        if (myActualPlayerId.equals(player1Id)) {
            return player1Score;
        } else if (myActualPlayerId.equals(player2Id)) {
            return player2Score;
        }
        return 0; // Mon ID ne correspond à aucun joueur ?
    }
}