"""Tests para setup_geo_stack_docker_pipeline.

Si los contenedores del geo stack están corriendo, verifica que el pipeline
devuelve flags coherentes. Si no, salta (stub: requiere infra externa).
"""

from __future__ import annotations

import os
import sys

import pytest

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

from python.functions.infra.docker_container_running import docker_container_running
from python.functions.pipelines.setup_geo_stack_docker_pipeline import (
    setup_geo_stack_docker_pipeline,
)

GEO_STACK_CONTAINERS = ("better_maps_valhalla", "better_maps_postgis", "better_maps_martin")


def test_setup_geo_stack_docker_pipeline_shape():
    """El pipeline siempre devuelve un dict con los 4 flags bool, aun sin docker."""
    result = setup_geo_stack_docker_pipeline(
        compose_path="apps/footprint_geo_stack/docker-compose.yml",
        wait_seconds=0,
        verify=True,
    )
    assert isinstance(result, dict)
    assert set(result.keys()) == {"docker_up", "valhalla_ok", "postgis_ok", "martin_ok"}
    for key in result:
        assert isinstance(result[key], bool), f"{key} debe ser bool"


def test_setup_geo_stack_docker_pipeline_live_stack():
    """Si los 3 contenedores están vivos, el pipeline debe reportar valhalla_ok=True."""
    if not all(docker_container_running(c) for c in GEO_STACK_CONTAINERS):
        pytest.skip(f"geo stack no está activo (contenedores esperados: {GEO_STACK_CONTAINERS})")

    result = setup_geo_stack_docker_pipeline(
        compose_path="apps/footprint_geo_stack/docker-compose.yml",
        wait_seconds=0,
        verify=True,
    )
    assert result["valhalla_ok"] is True, "Valhalla container vivo pero el flag dice False"
