"""Tests for DocumentSchedulerSettings dataclass.

Note: More comprehensive tests for the TTL-cached settings retrieval are in
test_settings_cache.py. These tests focus on the dataclass itself.
"""

from dataclasses import FrozenInstanceError

import pytest

from src.local_deep_research.news.subscription_manager.scheduler import (
    DocumentSchedulerSettings,
)


class TestDocumentSchedulerSettings:
    """Tests for the DocumentSchedulerSettings frozen dataclass."""

    def test_default_values(self):
        """Dataclass has correct default values."""
        settings = DocumentSchedulerSettings()

        assert settings.enabled is True
        assert settings.interval_seconds == 1800
        assert settings.download_pdfs is False
        assert settings.extract_text is True
        assert settings.generate_rag is False
        assert settings.last_run == ""

    def test_custom_values(self):
        """Dataclass accepts custom values."""
        settings = DocumentSchedulerSettings(
            enabled=False,
            interval_seconds=3600,
            download_pdfs=True,
            extract_text=False,
            generate_rag=True,
            last_run="2025-01-01T00:00:00+00:00",
        )

        assert settings.enabled is False
        assert settings.interval_seconds == 3600
        assert settings.download_pdfs is True
        assert settings.extract_text is False
        assert settings.generate_rag is True
        assert settings.last_run == "2025-01-01T00:00:00+00:00"

    def test_partial_values(self):
        """Dataclass accepts partial values with defaults for the rest."""
        settings = DocumentSchedulerSettings(
            enabled=False,
            download_pdfs=True,
        )

        assert settings.enabled is False
        assert settings.interval_seconds == 1800  # default
        assert settings.download_pdfs is True
        assert settings.extract_text is True  # default
        assert settings.generate_rag is False  # default
        assert settings.last_run == ""  # default

    def test_frozen_immutability(self):
        """Frozen dataclass raises FrozenInstanceError on mutation."""
        settings = DocumentSchedulerSettings()

        with pytest.raises(FrozenInstanceError):
            settings.enabled = False

    def test_defaults_classmethod(self):
        """defaults() classmethod returns default settings instance."""
        defaults = DocumentSchedulerSettings.defaults()

        assert defaults.enabled is True
        assert defaults.interval_seconds == 1800
        assert defaults.download_pdfs is False
        assert defaults.extract_text is True
        assert defaults.generate_rag is False
        assert defaults.last_run == ""
