"""Simple nearest distance altitude setter for smart convolve."""

from typing import TYPE_CHECKING

import numpy as np

if TYPE_CHECKING:
    from collections.abc import Sequence

    from gri_pos import LLA


def nearest(inputs: Sequence[tuple[LLA, list[LLA]]]) -> list[float]:
    """Take a list of (LLA, list[LLA]) and output the nearest altitude in list.

    Args:
        inputs(Sequence[tuple[LLA, list[LLA]]]): The LLA point to find the nearest
            altitude to, and the list of LLA points to search for the nearest point.

    Returns:
        list of altitudes in the same order as points
    """
    alts: list[float] = []
    for lla, points in inputs:
        dist = [lla.dist_surface_simple_m(p) for p in points]
        idx = np.argmin(dist)
        alts.append(points[idx].alt_m)
    return alts
