from datetime import datetime, timezone

from backend.app.models import StationModel, TrackModel, TrainModel


def _now() -> datetime:
    return datetime.now(timezone.utc)


def test_station_model_round_trip() -> None:
    timestamp = _now()
    station = StationModel(
        id="station-1",
        name="Central",
        latitude=52.52,
        longitude=13.405,
        created_at=timestamp,
        updated_at=timestamp,
    )
    assert station.name == "Central"
    assert station.model_dump()["id"] == "station-1"


def test_track_model_properties() -> None:
    timestamp = _now()
    track = TrackModel(
        id="track-1",
        start_station_id="station-1",
        end_station_id="station-2",
        length_meters=1500.0,
        max_speed_kph=120.0,
        status="operational",
        is_bidirectional=True,
        coordinates=[(52.52, 13.405), (52.6, 13.5)],
        created_at=timestamp,
        updated_at=timestamp,
    )
    assert track.length_meters > 0
    assert track.start_station_id != track.end_station_id
    assert len(track.coordinates) == 2


def test_train_model_operating_tracks() -> None:
    timestamp = _now()
    train = TrainModel(
        id="train-1",
        designation="Express",
        capacity=350,
        max_speed_kph=200.0,
        operating_track_ids=["track-1", "track-2"],
        created_at=timestamp,
        updated_at=timestamp,
    )
    assert train.capacity >= 0
    assert len(train.operating_track_ids) == 2
