"""Known-value regression guards for pyfitparsernative."""

from datetime import datetime

from .conftest import SAMPLE_FIT, messages_by_type


def test_known_record_count():
    from pyfitparsernative import parse_fit_file

    records = messages_by_type(parse_fit_file(SAMPLE_FIT))["record"]
    assert len(records) == 9979


def test_known_timestamp_format():
    """Timestamps are naive ISO 8601 strings that can be parsed by datetime.fromisoformat."""
    from pyfitparsernative import parse_fit_file

    records = messages_by_type(parse_fit_file(SAMPLE_FIT))["record"]
    ts = records[0]["timestamp"]
    assert isinstance(ts, str)
    parsed = datetime.fromisoformat(ts)
    assert parsed.tzinfo is None, "timestamp should be naive (no timezone)"
    assert parsed == datetime(2026, 1, 31, 13, 41, 14)


def test_known_session_values():
    from pyfitparsernative import parse_fit_file

    session = messages_by_type(parse_fit_file(SAMPLE_FIT))["session"][0]
    assert session["avg_power"] == 160
    assert session["max_power"] == 489
    assert session["normalized_power"] == 184
    assert session["avg_heart_rate"] == 119
    assert session["max_heart_rate"] == 142
    assert session["avg_cadence"] == 75
    assert session["max_cadence"] == 102
    assert session["total_calories"] == 1864
    assert session["total_ascent"] == 494
    assert session["total_descent"] == 495
    assert session["total_work"] == 1597734
    assert session["avg_temperature"] == 16
    assert session["max_temperature"] == 25
