package com.openosrs.client.api.types;

public class Position {
    private final int x;
    private final int y;
    private final int plane;

    public Position(int x, int y, int plane) {
        this.x = x;
        this.y = y;
        this.plane = plane;
    }

    public int getX() { return x; }
    public int getY() { return y; }
    public int getPlane() { return plane; }

    public double distanceTo(Position other) {
        if (other.plane != this.plane) {
            return Double.MAX_VALUE; // Different planes
        }
        int dx = other.x - this.x;
        int dy = other.y - this.y;
        return Math.sqrt(dx * dx + dy * dy);
    }

    public Position offset(int dx, int dy) {
        return new Position(x + dx, y + dy, plane);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (!(obj instanceof Position)) return false;
        Position other = (Position) obj;
        return x == other.x && y == other.y && plane == other.plane;
    }

    @Override
    public int hashCode() {
        return 31 * (31 * x + y) + plane;
    }

    @Override
    public String toString() {
        return String.format("Position(%d, %d, %d)", x, y, plane);
    }
}
