"""Tests for domain classifier models."""

from unittest.mock import MagicMock


class TestDomainClassificationModel:
    """Tests for DomainClassification model."""

    def test_to_dict_returns_dict(self, mock_domain_classification):
        """Should return dictionary representation."""
        result = mock_domain_classification.to_dict()
        assert isinstance(result, dict)

    def test_to_dict_has_expected_keys(self, mock_domain_classification):
        """Should have all expected keys."""
        # Set up to_dict to return a dict
        mock_domain_classification.to_dict = lambda: {
            "id": mock_domain_classification.id,
            "domain": mock_domain_classification.domain,
            "category": mock_domain_classification.category,
            "subcategory": mock_domain_classification.subcategory,
            "confidence": mock_domain_classification.confidence,
            "reasoning": mock_domain_classification.reasoning,
            "sample_titles": mock_domain_classification.sample_titles,
            "sample_count": mock_domain_classification.sample_count,
            "created_at": mock_domain_classification.created_at.isoformat()
            if mock_domain_classification.created_at
            else None,
            "updated_at": mock_domain_classification.updated_at.isoformat()
            if mock_domain_classification.updated_at
            else None,
        }

        result = mock_domain_classification.to_dict()

        expected_keys = [
            "id",
            "domain",
            "category",
            "subcategory",
            "confidence",
            "reasoning",
            "sample_titles",
            "sample_count",
            "created_at",
            "updated_at",
        ]
        for key in expected_keys:
            assert key in result

    def test_to_dict_formats_timestamps(self, mock_domain_classification):
        """Should format timestamps as ISO format strings."""
        mock_domain_classification.to_dict = lambda: {
            "created_at": mock_domain_classification.created_at.isoformat()
            if mock_domain_classification.created_at
            else None,
            "updated_at": mock_domain_classification.updated_at.isoformat()
            if mock_domain_classification.updated_at
            else None,
        }

        result = mock_domain_classification.to_dict()

        assert "T" in result["created_at"]  # ISO format contains T
        assert "T" in result["updated_at"]

    def test_to_dict_handles_none_timestamps(self):
        """Should handle None timestamps."""
        classification = MagicMock()
        classification.id = 1
        classification.domain = "test.com"
        classification.category = "Other"
        classification.subcategory = "Unknown"
        classification.confidence = 0.5
        classification.reasoning = None
        classification.sample_titles = None
        classification.sample_count = 0
        classification.created_at = None
        classification.updated_at = None
        classification.to_dict = lambda: {
            "created_at": None,
            "updated_at": None,
        }

        result = classification.to_dict()

        assert result["created_at"] is None
        assert result["updated_at"] is None
