# #region Test.Models.Dashboard [C:1] [TYPE Module] [SEMANTICS test,models,dashboard,pydantic]
# @BRIEF Tests for models/dashboard.py — DashboardMetadata, DashboardSelection.
# @RELATION BINDS_TO -> [DashboardModels]
# @TEST_EDGE: missing_field -> optional fields default correctly
# @TEST_EDGE: invalid_type -> Pydantic validation rejects bad types
# @TEST_EDGE: serialization -> round-trip via model_dump/model_validate

from datetime import datetime, timezone
import pytest
from pydantic import ValidationError


class TestDashboardMetadata:
    """DashboardMetadata — Pydantic model for dashboard metadata."""

    def test_minimal(self):
        from src.models.dashboard import DashboardMetadata

        dm = DashboardMetadata(id=42, title="Sales", last_modified="2024-01-15", status="active")
        assert dm.id == 42
        assert dm.title == "Sales"
        assert dm.last_modified == "2024-01-15"
        assert dm.status == "active"

    def test_missing_required_raises(self):
        from src.models.dashboard import DashboardMetadata

        with pytest.raises(ValidationError):
            DashboardMetadata(title="Sales", last_modified="2024-01-15", status="active")
        with pytest.raises(ValidationError):
            DashboardMetadata(id=42, last_modified="2024-01-15", status="active")
        with pytest.raises(ValidationError):
            DashboardMetadata(id=42, title="Sales", status="active")
        with pytest.raises(ValidationError):
            DashboardMetadata(id=42, title="Sales", last_modified="2024-01-15")

    def test_serialize_roundtrip(self):
        from src.models.dashboard import DashboardMetadata

        dm = DashboardMetadata(id=1, title="Test", last_modified="2024-06-15", status="archived")
        data = dm.model_dump()
        restored = DashboardMetadata.model_validate(data)
        assert restored.id == 1
        assert restored.title == "Test"
        assert restored.status == "archived"


class TestDashboardSelection:
    """DashboardSelection — user selection of dashboards to migrate."""

    def test_minimal(self):
        from src.models.dashboard import DashboardSelection

        ds = DashboardSelection(selected_ids=[1, 2, 3], source_env_id="src-1", target_env_id="tgt-1")
        assert ds.selected_ids == [1, 2, 3]
        assert ds.source_env_id == "src-1"
        assert ds.target_env_id == "tgt-1"
        assert ds.replace_db_config is False
        assert ds.fix_cross_filters is True

    def test_with_options(self):
        from src.models.dashboard import DashboardSelection

        ds = DashboardSelection(
            selected_ids=[42], source_env_id="e1", target_env_id="e2",
            replace_db_config=True, fix_cross_filters=False,
        )
        assert ds.replace_db_config is True
        assert ds.fix_cross_filters is False

    def test_missing_required_raises(self):
        from src.models.dashboard import DashboardSelection

        with pytest.raises(ValidationError):
            DashboardSelection()
        with pytest.raises(ValidationError):
            DashboardSelection(selected_ids=[], source_env_id="s1")
        with pytest.raises(ValidationError):
            DashboardSelection(selected_ids=[1], target_env_id="t1")

    def test_serialize_roundtrip(self):
        from src.models.dashboard import DashboardSelection

        ds = DashboardSelection(selected_ids=[1], source_env_id="s1", target_env_id="t1", replace_db_config=True)
        data = ds.model_dump()
        restored = DashboardSelection.model_validate(data)
        assert restored.selected_ids == [1]
        assert restored.replace_db_config is True
        assert restored.fix_cross_filters is True
# #endregion Test.Models.Dashboard
