"""Tests for Piggie graph types."""

import pytest

from piggie.types import Edge, Path, Vertex


def test_vertex_creation():
    v = Vertex(id=1, label="Person", properties={"name": "Alice", "age": 30})
    assert v.id == 1
    assert v.label == "Person"
    assert v.properties == {"name": "Alice", "age": 30}


def test_vertex_getitem():
    v = Vertex(id=1, label="Person", properties={"name": "Alice"})
    assert v["name"] == "Alice"
    assert v["missing"] is None


def test_vertex_frozen():
    v = Vertex(id=1, label="Person", properties={"name": "Alice"})
    with pytest.raises(AttributeError):
        v.id = 2  # type: ignore[misc]


def test_edge_creation():
    e = Edge(id=10, label="KNOWS", start_id=1, end_id=2, properties={"since": 2020})
    assert e.id == 10
    assert e.label == "KNOWS"
    assert e.start_id == 1
    assert e.end_id == 2
    assert e["since"] == 2020


def test_path_creation():
    v1 = Vertex(id=1, label="Person", properties={"name": "Alice"})
    e = Edge(id=10, label="KNOWS", start_id=1, end_id=2, properties={})
    v2 = Vertex(id=2, label="Person", properties={"name": "Bob"})
    p = Path(entities=(v1, e, v2))
    assert len(p) == 3
    assert p.vertices == [v1, v2]
    assert p.edges == [e]
    assert list(p) == [v1, e, v2]
    assert p[0] == v1
    assert p[1] == e


def test_vertex_repr():
    v = Vertex(id=1, label="Person", properties={"name": "Alice"})
    r = repr(v)
    assert "Person" in r
    assert "Alice" in r


def test_edge_repr():
    e = Edge(id=10, label="KNOWS", start_id=1, end_id=2, properties={})
    r = repr(e)
    assert "KNOWS" in r
    assert "start_id=1" in r


def test_path_repr():
    v1 = Vertex(id=1, label="A", properties={})
    e = Edge(id=10, label="R", start_id=1, end_id=2, properties={})
    v2 = Vertex(id=2, label="B", properties={})
    p = Path(entities=(v1, e, v2))
    assert "length=1" in repr(p)
