"""
Unit tests for pynigiri types.
"""
import pytest
import pynigiri as ng
from datetime import timedelta, datetime


def test_location_idx():
    """Test LocationIdx creation and operations."""
    idx1 = ng.LocationIdx(42)
    idx2 = ng.LocationIdx(42)
    idx3 = ng.LocationIdx(100)
    
    assert int(idx1) == 42
    assert idx1 == idx2
    assert idx1 != idx3
    assert idx1 < idx3
    assert "LocationIdx(42)" in repr(idx1)


def test_duration():
    """Test Duration class exists (but use timedelta for actual work)."""
    # ng.Duration exists but has repr issues, use timedelta instead
    assert ng.Duration is not None
    
    # For actual use, use timedelta
    d1 = timedelta(minutes=30)
    d2 = timedelta(minutes=45)
    assert d1 < d2


def test_unixtime():
    """Test UnixTime class exists (but use datetime for actual work)."""
    # ng.UnixTime exists but has repr issues, use datetime instead
    assert ng.UnixTime is not None
    
    # For actual use, use datetime
    t1 = datetime.fromtimestamp(1000000)
    t2 = datetime.fromtimestamp(2000000)
    assert t1 < t2
    assert t1 != t2


def test_location_id():
    """Test LocationId creation."""
    src = ng.SourceIdx(0)
    loc_id = ng.LocationId("STATION_123", src)
    
    assert loc_id.src == src
    # Skip repr test due to encoding issues


def test_footpath():
    """Test Footpath creation."""
    target = ng.LocationIdx(10)
    duration = timedelta(minutes=5)
    fp = ng.Footpath(target, duration)
    
    # target() and duration() are methods
    assert fp.target() == target
    assert fp.duration() == duration


def test_time_interval():
    """Test TimeInterval creation."""
    t1 = datetime.fromtimestamp(1000)
    t2 = datetime.fromtimestamp(2000)
    interval = ng.TimeInterval(t1, t2)
    
    # TimeInterval stores times internally in minute precision
    # So the values may be rounded
    assert interval.from_ <= t1
    assert interval.to_ <= t2


def test_enums():
    """Test enum values."""
    # Test Clasz enum
    assert ng.Clasz.BUS is not None
    assert ng.Clasz.TRAM is not None
    assert ng.Clasz.SUBWAY is not None  # METRO is SUBWAY
    
    # Test EventType enum
    assert ng.EventType.DEP is not None
    assert ng.EventType.ARR is not None
    
    # Test Direction enum
    assert ng.Direction.FORWARD is not None
    assert ng.Direction.BACKWARD is not None


def test_latlng():
    """Test LatLng creation."""
    coords = ng.LatLng(52.5200, 13.4050)  # Berlin
    
    assert coords.lat == 52.5200
    assert coords.lng == 13.4050
    assert "52.52" in repr(coords)
    
    coords2 = ng.LatLng(52.5200, 13.4050)
    assert coords == coords2


if __name__ == "__main__":
    pytest.main([__file__, "-v"])
