"""Domain.services.segmentation_service
Where: Domain service module providing reusable business logic.
What: Houses service routines and helpers implemented in this module.
Why: Makes this service behaviour accessible to application workflows.
"""

from __future__ import annotations


class SegmentationService:
    """文分割と行マッピングの補助サービス（純粋関数）。"""

    def split_sentences_with_lines(self, lines: list[str]) -> tuple[list[str], list[int]]:
        """
        Split lines into sentences and map each sentence to its source line.

        Purpose:
            Segment text by sentence boundaries (Japanese period) while tracking
            which source line each sentence originated from.

        Args:
            lines: List of text lines to segment.

        Returns:
            Tuple of (sentences, line_map) where line_map[i] is the source line
            number (1-indexed) for sentences[i].

        Side Effects:
            None (pure function).
        """
        sentences: list[str] = []
        line_map: list[int] = []
        for idx, line in enumerate(lines, 1):
            work = (line or "").strip()
            if not work:
                continue
            parts = [p for p in work.split("。") if p.strip()]
            for p in parts:
                sentences.append(p)
                line_map.append(idx)
        return sentences, line_map
