"""Annotation entity for user-created annotations during recording.

Distinct from LLM-extracted ActionItem/KeyPoint in summaries.
"""

from __future__ import annotations

from dataclasses import dataclass, field
from datetime import datetime
from typing import TYPE_CHECKING

from noteflow.domain.utils.time import utc_now
from noteflow.domain.utils.validation import validate_time_range

if TYPE_CHECKING:
    from noteflow.domain.value_objects import AnnotationId, AnnotationType, MeetingId


@dataclass
class Annotation:
    """User-created annotation during recording.

    Evidence-linked to specific transcript segments for navigation.
    Unlike ActionItem/KeyPoint (LLM-extracted from Summary), annotations
    are created in real-time during recording and belong directly to Meeting.
    """

    id: AnnotationId
    meeting_id: MeetingId
    annotation_type: AnnotationType
    text: str
    start_time: float
    end_time: float
    segment_ids: list[int] = field(default_factory=list)
    created_at: datetime = field(default_factory=utc_now)

    # Database primary key (set after persistence)
    db_id: int | None = None

    def __post_init__(self) -> None:
        """Validate annotation data."""
        validate_time_range(self.start_time, self.end_time)

    @property
    def duration(self) -> float:
        """Annotation duration in seconds."""
        return self.end_time - self.start_time

    def has_segments(self) -> bool:
        """Check if annotation is linked to transcript segments."""
        return len(self.segment_ids) > 0
