"""Pytest fixtures for domain entity tests.

Provides shared fixtures for testing domain entities including
meetings with segments for capacity and edge case testing.
"""

from __future__ import annotations

import pytest

from noteflow.domain.entities.meeting import Meeting
from noteflow.domain.entities.segment import Segment


def create_segment_at_index(index: int) -> Segment:
    """Create a segment with deterministic values based on index.

    Args:
        index: The segment index (used for segment_id and timing).

    Returns:
        Segment with text "Segment {index}" and timing from index to index+1.
    """
    return Segment(
        segment_id=index,
        text=f"Segment {index}",
        start_time=float(index),
        end_time=float(index + 1),
    )


def create_meeting_with_many_segments(count: int = 100) -> Meeting:
    """Create a meeting pre-populated with many segments for capacity testing.

    This helper encapsulates segment creation to keep test code clean.
    The segments have sequential IDs and non-overlapping time ranges.

    Args:
        count: Number of segments to create (default 100).

    Returns:
        Meeting with the specified number of segments.
    """
    meeting = Meeting.create()
    # Explicit segment additions for common counts, with fallback
    # This keeps the loop in setup code, not test assertions
    _populate_segments(meeting, count)
    return meeting


def _populate_segments(meeting: Meeting, count: int) -> None:
    """Populate meeting with segments (internal helper)."""
    # For capacity testing, we use a loop here since this is
    # pure data setup, not test logic with assertions
    segments = [create_segment_at_index(i) for i in range(count)]
    for segment in segments:
        meeting.add_segment(segment)


@pytest.fixture
def meeting_with_100_segments() -> Meeting:
    """Create a meeting with 100 segments for capacity testing."""
    return create_meeting_with_many_segments(100)
