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

package pp.battleship.message.client;

import com.jme3.network.serializing.Serializable;
import pp.battleship.model.Battleship;

import java.util.ArrayList;
import java.util.List;

/**
 * A message sent by the client containing the positions of the ships on the player's map.
 */
@Serializable
public class MapMessage extends ClientMessage {
    private List<Battleship> ships;

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

    /**
     * Constructs a MapMessage with the specified list of ships.
     *
     * @param ships the list of ships placed on the player's map
     */
    public MapMessage(List<Battleship> ships) {
        this.ships = new ArrayList<>(ships);
    }

    /**
     * Returns the list of ships on the player's map.
     *
     * @return the list of ships
     */
    public List<Battleship> getShips() {
        return ships;
    }

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

    /**
     * Accepts a visitor to process this message.
     *
     * @param interpreter the visitor to process this message
     * @param from        the connection ID from which the message was received
     */
    @Override
    public void accept(ClientInterpreter interpreter, int from) {
        interpreter.received(this, from);
    }
}
