"""Tests para valhalla_isochrone."""

from __future__ import annotations

import sys
import os

sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))

import httpx
import pytest

from valhalla_isochrone import valhalla_isochrone


def _valhalla_alive(url: str = "http://localhost:8002") -> bool:
    try:
        r = httpx.get(f"{url}/status", timeout=2.0)
        return r.status_code < 500
    except Exception:
        return False


VALHALLA_OK = _valhalla_alive()
skip_if_no_valhalla = pytest.mark.skipif(
    not VALHALLA_OK, reason="Valhalla no activo en :8002"
)


@skip_if_no_valhalla
def test_isócrona_10_min_madrid_contiene_features():
    """isócrona 10 min Madrid contiene features"""
    gj = valhalla_isochrone(lat=40.4168, lon=-3.7038, minutes=10)
    assert gj is not None, "Esperaba GeoJSON, obtuvo None"
    assert "features" in gj, "GeoJSON no contiene 'features'"
    assert len(gj["features"]) > 0, "features está vacío"
