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

package pp.battleship.model.dto;

import pp.battleship.model.Battleship;
import pp.battleship.model.Rotation;

/**
 * A class representing data transfer objects of battleships for JSON serialization and deserialization.
 */
class BattleshipDTO {
    private final int length;   // The length of the battleship
    private final int x;        // The x-coordinate of the battleship's position
    private final int y;        // The y-coordinate of the battleship's position
    private final Rotation rot; // The rotation of the battleship

    /**
     * Constructs a BattleshipDTO object from a Battleship object.
     *
     * @param ship the Battleship object to be converted
     */
    BattleshipDTO(Battleship ship) {
        length = ship.getLength();
        x = ship.getX();
        y = ship.getY();
        rot = ship.getRot();
    }

    /**
     * Gets the length of the battleship.
     *
     * @return the length
     */
    public int getLength() {
        return length;
    }

    /**
     * Converts this BattleshipDTO object to a Battleship object.
     *
     * @return the Battleship object
     */
    Battleship toBattleship() {
        return new Battleship(length, x, y, rot);
    }
}
