from datetime import UTC, datetime

from ww_core.domain.project_repo import _to_view, max_time
from ww_db.models import Project


def test_to_view_carries_tone_ending_pov() -> None:
    # ④ 立项三字段（基调/结局/视角）经 ORM 行 → ProjectView 快照逐字段透传（snake_case）。
    row = Project(title="书", tone="热血", ending_type="BE", narrative_pov="多视角")
    view = _to_view(row)
    assert view.tone == "热血"
    assert view.ending_type == "BE"
    assert view.narrative_pov == "多视角"


def test_max_time_handles_missing_values() -> None:
    now = datetime(2026, 6, 28, tzinfo=UTC)

    assert max_time(None, None) is None
    assert max_time(now, None) == now
    assert max_time(None, now) == now


def test_max_time_returns_latest_value() -> None:
    early = datetime(2026, 6, 27, tzinfo=UTC)
    late = datetime(2026, 6, 28, tzinfo=UTC)

    assert max_time(early, late) == late
    assert max_time(late, early) == late
