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

package pp.battleship.model;

import java.io.Serializable;

/**
 * Represents the rotation of a ship and provides functionality related to rotation.
 */
public enum Rotation implements Serializable {
    /**
     * Represents the ship facing upwards.
     */
    UP,
    /**
     * Represents the ship facing rightwards.
     */
    RIGHT,
    /**
     * Represents the ship facing downwards.
     */
    DOWN,
    /**
     * Represents the ship facing leftwards.
     */
    LEFT;

    /**
     * Gets the change in x-coordinate corresponding to this rotation.
     *
     * @return the change in x-coordinate
     */
    public int dx() {
        return switch (this) {
            case UP, DOWN -> 0;
            case RIGHT -> 1;
            case LEFT -> -1;
        };
    }

    /**
     * Gets the change in y-coordinate corresponding to this rotation.
     *
     * @return the change in y-coordinate
     */
    public int dy() {
        return switch (this) {
            case UP -> 1;
            case LEFT, RIGHT -> 0;
            case DOWN -> -1;
        };
    }

    /**
     * Rotates the orientation clockwise and returns the next rotation.
     *
     * @return the next rotation after rotating clockwise
     */
    public Rotation rotate() {
        return values()[(ordinal() + 1) % values().length];
    }
}
