////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////

package pp.battleship.message.server;

import com.jme3.network.serializing.Serializable;

/**
 * A message sent by the server to inform clients about the start of the battle.
 */
@Serializable
public class StartBattleMessage extends ServerMessage {
    private boolean myTurn;

    /**
     * Default constructor for serialization purposes.
     */
    private StartBattleMessage() { /* empty */ }

    /**
     * Constructs a StartBattleMessage with the specified turn indicator.
     *
     * @param myTurn true if it's the client's turn to shoot, false otherwise
     */
    public StartBattleMessage(boolean myTurn) {
        this.myTurn = myTurn;
    }

    /**
     * Accepts a visitor to process this message.
     *
     * @param interpreter the visitor to process this message
     */
    @Override
    public void accept(ServerInterpreter interpreter) {
        interpreter.received(this);
    }

    /**
     * Checks if it's the client's turn to shoot.
     *
     * @return true if it's the client's turn, false otherwise
     */
    public boolean isMyTurn() {
        return myTurn;
    }

    /**
     * Returns a string representation of the StartBattleMessage.
     *
     * @return a string representation of the StartBattleMessage
     */
    @Override
    public String toString() {
        return "StartBattleMessage{myTurn=" + myTurn + '}'; //NON-NLS
    }

    /**
     * Returns the key for the informational text associated with this message.
     *
     * @return the key for the informational text
     */
    @Override
    public String getInfoTextKey() {
        return isMyTurn() ? "its.your.turn" : "wait.for.opponent";
    }
}
