"""Helper script to generate intermediate stops along a route."""
from typing import List, Tuple

def interpolate_point(
    start: Tuple[float, float],
    end: Tuple[float, float],
    fraction: float
) -> Tuple[float, float]:
    """Interpolate a point between start and end coordinates."""
    lat = start[0] + (end[0] - start[0]) * fraction
    lng = start[1] + (end[1] - start[1]) * fraction
    return (lat, lng)

def generate_intermediate_stops(
    start_coords: Tuple[float, float],
    end_coords: Tuple[float, float],
    num_stops: int,
    start_name: str = "Start",
    end_name: str = "End",
    city: str = "Route"
) -> List[dict]:
    """Generate intermediate stops along a route.
    
    Args:
        start_coords: (latitude, longitude) of start point
        end_coords: (latitude, longitude) of end point
        num_stops: Total number of stops to generate (including start and end)
        start_name: Name of the start stop
        end_name: Name of the end stop
        city: City name for intermediate stops
    
    Returns:
        List of stop dictionaries with name, lat, lng, city
    """
    if num_stops < 2:
        return [
            {"name": start_name, "lat": start_coords[0], "lng": start_coords[1], "city": city},
            {"name": end_name, "lat": end_coords[0], "lng": end_coords[1], "city": city}
        ]
    
    stops = []
    
    # Add start stop
    stops.append({
        "name": start_name,
        "lat": start_coords[0],
        "lng": start_coords[1],
        "city": city
    })
    
    # Generate intermediate stops
    for i in range(1, num_stops - 1):
        fraction = i / (num_stops - 1)
        lat, lng = interpolate_point(start_coords, end_coords, fraction)
        
        # Generate realistic stop names
        stop_name = f"Parada {i}"
        if i % 10 == 0:
            stop_name = f"Parada Principal {i // 10}"
        elif i % 5 == 0:
            stop_name = f"Intersección {i // 5}"
        
        stops.append({
            "name": stop_name,
            "lat": lat,
            "lng": lng,
            "city": city
        })
    
    # Add end stop
    stops.append({
        "name": end_name,
        "lat": end_coords[0],
        "lng": end_coords[1],
        "city": city
    })
    
    return stops

# Example: Generate 61 stops for Boquete>David route
if __name__ == "__main__":
    # Boquete coordinates (Terminal)
    boquete_start = (8.7697, -82.4328)
    # David coordinates (Terminal)
    david_end = (8.4177, -82.4270)
    
    stops = generate_intermediate_stops(
        boquete_start,
        david_end,
        num_stops=61,
        start_name="Terminal de Boquete",
        end_name="Terminal de David",
        city="Ruta Boquete-David"
    )
    
    print(f"Generated {len(stops)} stops:")
    for i, stop in enumerate(stops, 1):
        print(f"{i:2d}. {stop['name']:30s} ({stop['lat']:.6f}, {stop['lng']:.6f})")

