"""Tests for duty_teller.services.import_service (_consecutive_date_ranges)."""

from datetime import date


from duty_teller.services.import_service import _consecutive_date_ranges


class TestConsecutiveDateRanges:
    """Unit tests for _consecutive_date_ranges."""

    def test_empty_returns_empty(self):
        assert _consecutive_date_ranges([]) == []

    def test_single_day_one_range(self):
        d = date(2025, 2, 10)
        assert _consecutive_date_ranges([d]) == [(d, d)]

    def test_consecutive_days_one_range(self):
        dates = [date(2025, 1, 10), date(2025, 1, 11), date(2025, 1, 12)]
        assert _consecutive_date_ranges(dates) == [
            (date(2025, 1, 10), date(2025, 1, 12)),
        ]

    def test_two_ranges_with_gap(self):
        dates = [
            date(2025, 1, 5),
            date(2025, 1, 6),
            date(2025, 1, 10),
            date(2025, 1, 11),
        ]
        assert _consecutive_date_ranges(dates) == [
            (date(2025, 1, 5), date(2025, 1, 6)),
            (date(2025, 1, 10), date(2025, 1, 11)),
        ]

    def test_unsorted_with_duplicates_normalized(self):
        dates = [
            date(2025, 1, 12),
            date(2025, 1, 10),
            date(2025, 1, 11),
            date(2025, 1, 10),
        ]
        assert _consecutive_date_ranges(dates) == [
            (date(2025, 1, 10), date(2025, 1, 12)),
        ]
