"""
Import and adapts utility functions from EveSolarSystem class
"""

import math

from eve_sde.models import SolarSystem


def distance_to(origin: SolarSystem, destination: SolarSystem) -> float:
    """Calculates the distance in meters between the current and the given solar system

    Args:
        destination: Other solar system to use in calculation

    Returns:
        Distance in meters or None if one of the systems is in WH space
    """
    if not origin.x or not origin.y or not origin.z:
        return 0.0
    if not destination or not destination.x or not destination.y or not destination.z:
        return 0

    if (
        origin.is_wh_space
        or destination.is_wh_space
        or origin.is_triglavian_space
        or destination.is_triglavian_space
    ):
        return 0

    return math.sqrt(
        (destination.x - origin.x) ** 2
        + (destination.y - origin.y) ** 2
        + (destination.z - origin.z) ** 2
    )
