"""
Test file to verify that dataclass inheritance from DomoEntity works correctly.

This test ensures that all dataclasses inheriting from DomoEntity properly
inherit the __eq__ method from DomoEntity instead of generating their own,
which prevents recursion errors and maintains consistent equality behavior.
"""

from domolibrary2.client.auth import DomoFullAuth


def test_domouser_equality():
    """Test that DomoUser properly inherits equality from DomoEntity."""
    from src.domolibrary2.classes.DomoUser import DomoUser

    auth = DomoFullAuth(
        domo_instance="test", domo_username="test", domo_password="test"
    )

    user1 = DomoUser(auth=auth, id="1", raw={}, Relations=None)
    user2 = DomoUser(auth=auth, id="1", raw={}, Relations=None)
    user3 = DomoUser(auth=auth, id="2", raw={}, Relations=None)

    # Same ID should be equal
    assert user1 == user2, "Users with same ID should be equal"

    # Different ID should not be equal
    assert user1 != user3, "Users with different IDs should not be equal"

    # Verify that __eq__ is inherited from DomoEntity, not generated by dataclass
    assert (
        user1.__class__.__eq__ is user1.__class__.__bases__[0].__eq__
    ), "Should inherit __eq__ from DomoEntity"


def test_domogroup_equality():
    """Test that DomoGroup properly inherits equality from DomoEntity."""
    from domolibrary2.classes.DomoGroup.core import DomoGroup

    auth = DomoFullAuth(
        domo_instance="test", domo_username="test", domo_password="test"
    )

    group1 = DomoGroup(auth=auth, id="1", raw={}, Relations=None)
    group2 = DomoGroup(auth=auth, id="1", raw={}, Relations=None)
    group3 = DomoGroup(auth=auth, id="2", raw={}, Relations=None)

    # Same ID should be equal
    assert group1 == group2, "Groups with same ID should be equal"

    # Different ID should not be equal
    assert group1 != group3, "Groups with different IDs should not be equal"

    # Verify that __eq__ is inherited from DomoEntity, not generated by dataclass
    assert (
        group1.__class__.__eq__ is group1.__class__.__bases__[0].__eq__
    ), "Should inherit __eq__ from DomoEntity"


def test_dataclass_eq_false_verification():
    """Test that all dataclasses that inherit from DomoEntity have eq=False."""
    from src.domolibrary2.classes.DomoAccount.account_default import DomoAccount_Default
    from src.domolibrary2.classes.DomoApplication.Job import DomoJob
    from src.domolibrary2.classes.DomoApplication.Job_Base import DomoJob_Base
    from src.domolibrary2.classes.DomoDataset.pdp import PDPPolicy
    from src.domolibrary2.classes.DomoDataset.stream import DomoStream
    from domolibrary2.classes.DomoGroup.core import DomoGroup
    from src.domolibrary2.classes.DomoInstanceConfig.access_token import DomoAccessToken
    from src.domolibrary2.classes.DomoInstanceConfig.api_client import ApiClient
    from src.domolibrary2.classes.DomoInstanceConfig.user_attributes import (
        UserAttribute,
    )
    from src.domolibrary2.classes.DomoUser import DomoUser

    # Test that these classes inherit __eq__ from DomoEntity instead of generating their own
    # Note: DomoIntegration removed due to import issues, DomoJupyterWorkspace has complex auth requirements
    dataclass_entities = [
        DomoUser,
        DomoGroup,
        DomoAccessToken,
        UserAttribute,
        ApiClient,
        DomoStream,
        DomoAccount_Default,
        DomoJob_Base,
        DomoJob,
        PDPPolicy,
    ]

    for cls in dataclass_entities:
        # Verify the class has DomoEntity as a base class
        assert any(
            base.__name__ == "DomoEntity" for base in cls.__mro__
        ), f"{cls.__name__} should inherit from DomoEntity"

        # Verify the class inherits __eq__ from DomoEntity rather than generating its own
        domoentity_base = next(
            base for base in cls.__mro__ if base.__name__ == "DomoEntity"
        )
        assert (
            cls.__eq__ is domoentity_base.__eq__
        ), f"{cls.__name__} should inherit __eq__ from DomoEntity, not generate its own"

        print(f"✓ {cls.__name__} properly inherits __eq__ from DomoEntity")


if __name__ == "__main__":
    # Run all tests when executed directly
    import os
    import sys

    sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))

    test_domouser_equality()
    test_domogroup_equality()
    test_dataclass_eq_false_verification()

    print("All dataclass inheritance equality tests passed!")
    print("The eq=False pattern is working correctly across all DomoEntity subclasses.")
