"""
Tests for DateNormalizer

Usage:
    pytest tests/normalize/normalizers/test_date_normalizer.py -v
"""

import pytest
from shared.normalize.normalizers.date_normalizer import DateNormalizer


class TestDateNormalizer:
    """Test DateNormalizer functionality"""

    @pytest.fixture
    def normalizer(self):
        """Create normalizer instance for testing"""
        return DateNormalizer()

    def test_iso_format(self, normalizer):
        """ISO format date should generate multiple variants"""
        result = normalizer.normalize('2025-12-13')
        assert '2025-12-13' in result
        assert '13/12/2025' in result
        assert '13.12.2025' in result

    def test_european_slash_format(self, normalizer):
        """European slash format should be parsed correctly"""
        result = normalizer.normalize('13/12/2025')
        assert '2025-12-13' in result

    def test_european_dot_format(self, normalizer):
        """European dot format should be parsed correctly"""
        result = normalizer.normalize('13.12.2025')
        assert '2025-12-13' in result

    def test_compact_format_yyyymmdd(self, normalizer):
        """Compact YYYYMMDD format should be parsed"""
        result = normalizer.normalize('20251213')
        assert '2025-12-13' in result

    def test_compact_format_yymmdd(self, normalizer):
        """Compact YYMMDD format should be parsed"""
        result = normalizer.normalize('251213')
        assert '2025-12-13' in result

    def test_short_year_dot_format(self, normalizer):
        """Short year dot format (DD.MM.YY) should be parsed"""
        result = normalizer.normalize('13.12.25')
        assert '2025-12-13' in result

    def test_swedish_month_name(self, normalizer):
        """Swedish full month name should be parsed"""
        result = normalizer.normalize('13 december 2025')
        assert '2025-12-13' in result

    def test_swedish_month_abbreviation(self, normalizer):
        """Swedish month abbreviation should be parsed"""
        result = normalizer.normalize('13 dec 2025')
        assert '2025-12-13' in result

    def test_generates_swedish_month_variants(self, normalizer):
        """Should generate Swedish month name variants"""
        result = normalizer.normalize('2025-12-13')
        assert '13 december 2025' in result
        assert '13 dec 2025' in result

    def test_generates_hyphen_month_abbrev_format(self, normalizer):
        """Should generate hyphen with month abbreviation format"""
        result = normalizer.normalize('2025-12-13')
        assert '13-DEC-25' in result

    def test_iso_with_time(self, normalizer):
        """ISO format with time should extract date part"""
        result = normalizer.normalize('2025-12-13 14:30:00')
        assert '2025-12-13' in result

    def test_ambiguous_date_generates_both(self, normalizer):
        """Ambiguous date should generate both DD/MM and MM/DD interpretations"""
        result = normalizer.normalize('01/02/2025')
        # Could be Feb 1 or Jan 2
        assert '2025-02-01' in result or '2025-01-02' in result

    def test_middle_dot_separator(self, normalizer):
        """Middle dot separator should be generated"""
        result = normalizer.normalize('2025-12-13')
        assert '2025·12·13' in result

    def test_spaced_format(self, normalizer):
        """Spaced format should be generated"""
        result = normalizer.normalize('2025-12-13')
        assert '2025 12 13' in result

    def test_empty_string(self, normalizer):
        """Empty string should return empty list"""
        result = normalizer('')
        assert result == []

    def test_none_value(self, normalizer):
        """None value should return empty list"""
        result = normalizer(None)
        assert result == []

    def test_callable_interface(self, normalizer):
        """Normalizer should be callable via __call__"""
        result = normalizer('2025-12-13')
        assert '2025-12-13' in result

    def test_invalid_date(self, normalizer):
        """Invalid date should return original only"""
        result = normalizer.normalize('2025-13-45')  # Invalid month and day
        assert '2025-13-45' in result
        # Should not crash, but won't generate ISO variant

    def test_2digit_year_cutoff(self, normalizer):
        """2-digit year should use 2000s for < 50, 1900s for >= 50"""
        result = normalizer.normalize('251213')  # 25 = 2025
        assert '2025-12-13' in result

        result = normalizer.normalize('991213')  # 99 = 1999
        assert '1999-12-13' in result
