////////////////////////////////////////
// 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;
import pp.battleship.BattleshipConfig;

import java.util.Map;

/**
 * A message sent by the server to provide details about the game configuration.
 */
@Serializable
public class GameDetails extends ServerMessage {
    private Map<Integer, Integer> shipNums;
    private int width;
    private int height;

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

    /**
     * Constructs a GameDetails message with the specified BattleshipConfig.
     *
     * @param config the BattleshipConfig containing game configuration details
     */
    public GameDetails(BattleshipConfig config) {
        this.shipNums = config.getShipNums();
        this.width = config.getMapWidth();
        this.height = config.getMapHeight();
    }

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

    /**
     * Returns a map where the keys represent ship lengths
     * and the values represent the number of ships of that length.
     *
     * @return a map of ship lengths to the number of ships
     */
    public Map<Integer, Integer> getShipNums() {
        return shipNums;
    }

    /**
     * Returns the width of the game map.
     *
     * @return the width of the game map
     */
    public int getWidth() {
        return width;
    }

    /**
     * Returns the height of the game map.
     *
     * @return the height of the game map
     */
    public int getHeight() {
        return height;
    }

    /**
     * Returns a string representation of the GameDetails message.
     *
     * @return a string representation of the GameDetails message
     */
    @Override
    public String toString() {
        return "GameDetails{" + "ships=" + getShipNums() + ", width=" + width + ", height=" + height + '}'; //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 "place.ships.in.your.map";
    }
}
