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

package pp.battleship.model;

import com.jme3.network.serializing.Serializable;

import java.util.Objects;

/**
 * Represents a point in the two-dimensional plane with integer coordinates.
 */
@Serializable
public final class IntPoint implements IntPosition {
    private int x;
    private int y;

    /**
     * Default constructor for serialization purposes.
     */
    private IntPoint() { /* do nothing */ }

    /**
     * Constructs a new IntPoint with the specified coordinates.
     *
     * @param x the x-coordinate of the point
     * @param y the y-coordinate of the point
     */
    public IntPoint(int x, int y) {
        this.x = x;
        this.y = y;
    }

    /**
     * Gets the x-coordinate of the point.
     *
     * @return the x-coordinate
     */
    @Override
    public int getX() {
        return x;
    }

    /**
     * Gets the y-coordinate of the point.
     *
     * @return the y-coordinate
     */
    @Override
    public int getY() {
        return y;
    }

    /**
     * Indicates whether some other object is "equal to" this one.
     *
     * @param obj the reference object with which to compare
     * @return true if this object is the same as the obj argument; false otherwise
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (obj == null || obj.getClass() != this.getClass()) return false;
        var that = (IntPoint) obj;
        return this.x == that.x &&
               this.y == that.y;
    }

    /**
     * Returns a hash code value for the IntPoint.
     *
     * @return a hash code value for this object
     */
    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }

    /**
     * Returns a string representation of the IntPoint.
     *
     * @return a string representation of the object
     */
    @Override
    public String toString() {
        return "IntPoint[" + //NON-NLS
               "x=" + x + ", " + //NON-NLS
               "y=" + y + ']'; //NON-NLS
    }
}
