import math


def impact_prediction(
    radius: float,
    target_altitude: float,
    vertical_speed: float,
    horizontal_speed: float,
    surface_gravity: float,
    ut: float,
):
    """impact_prediction

    Extended description of function.

    Args:
        radius: current radius from center of body
        target_altitude: surface altitude
        vertical_speed: vertical speed
        horizontal_speed: horizontal speed
        surface_gravity: surface gravity
        ut: current ut

    Returns:
        return (None, None) if not impact
        return (impact_ut, terminal_speed)
    """
    fall_speed = -vertical_speed
    downward_acceleration = (
        surface_gravity - horizontal_speed * horizontal_speed / radius
    )

    # do we already landed?
    if target_altitude < 0:
        return None, None

    # do we land?
    if downward_acceleration < 0:
        max_fall_distance = -(fall_speed * fall_speed) / (
            2.0 * downward_acceleration
        )
        if max_fall_distance < (target_altitude + 1.0):
            return None, None

    sec_until_impact = (
        -fall_speed
        + math.sqrt(
            fall_speed * fall_speed
            + 2.0 * downward_acceleration * target_altitude
        )
    ) / downward_acceleration

    vertical_speed_at_impact = (
        fall_speed + sec_until_impact * downward_acceleration
    )
    impact_speed = math.sqrt(
        vertical_speed_at_impact * vertical_speed_at_impact
        + horizontal_speed * horizontal_speed
    )
    impact_ut = sec_until_impact + ut
    return impact_ut, impact_speed