from django.test import SimpleTestCase

from routing.models import SolarSystemConnection, TrigInvasion


class SolarSystemConnectionModelTest(SimpleTestCase):
    def test_weight_defaults(self) -> None:
        self.assertEqual(SolarSystemConnection._meta.get_field("p_shortest").default, 1)
        self.assertEqual(SolarSystemConnection._meta.get_field("p_safest").default, 1)
        self.assertEqual(SolarSystemConnection._meta.get_field("p_less_safe").default, 1)

    def test_unique_together(self) -> None:
        self.assertIn(("fromsolarsystem", "tosolarsystem"), SolarSystemConnection._meta.unique_together)


class TrigInvasionModelTest(SimpleTestCase):
    def test_status_choices(self) -> None:
        statuses = [value for value, _label in TrigInvasion.Status.choices]
        self.assertIn(TrigInvasion.Status.EDENCOM_MINOR_VICTORY, statuses)
        self.assertIn(TrigInvasion.Status.FINAL_LIMINALITY, statuses)
        self.assertIn(TrigInvasion.Status.FORTRESS, statuses)
        self.assertIn(TrigInvasion.Status.TRIGLAVIAN_MINOR_VICTORY, statuses)

    def test_system_field_is_primary_key(self) -> None:
        field = TrigInvasion._meta.get_field("system")
        self.assertTrue(field.primary_key)

    def test_status_field_max_length(self) -> None:
        field = TrigInvasion._meta.get_field("status")
        self.assertEqual(field.max_length, 50)


class SolarSystemConnectionIntegrationTest(SimpleTestCase):
    """Integration tests for SolarSystemConnection model constraints"""

    def test_unique_together_constraint_exists(self) -> None:
        """Verify from/to system pair cannot be duplicated"""
        unique_together = SolarSystemConnection._meta.unique_together
        self.assertIn(("fromsolarsystem", "tosolarsystem"), unique_together)

    def test_weight_fields_are_numeric(self) -> None:
        """Verify weight fields are float fields"""
        p_shortest = SolarSystemConnection._meta.get_field("p_shortest")
        p_safest = SolarSystemConnection._meta.get_field("p_safest")
        p_less_safe = SolarSystemConnection._meta.get_field("p_less_safe")

        self.assertEqual(p_shortest.__class__.__name__, "FloatField")
        self.assertEqual(p_safest.__class__.__name__, "FloatField")
        self.assertEqual(p_less_safe.__class__.__name__, "FloatField")


class TrigInvasionIntegrationTest(SimpleTestCase):
    """Integration tests for TrigInvasion model"""

    def test_all_status_values_defined(self) -> None:
        """Verify all expected status values exist"""
        status_values = [
            TrigInvasion.Status.EDENCOM_MINOR_VICTORY,
            TrigInvasion.Status.FINAL_LIMINALITY,
            TrigInvasion.Status.FORTRESS,
            TrigInvasion.Status.TRIGLAVIAN_MINOR_VICTORY,
        ]
        # Verify we can access each status
        for status in status_values:
            self.assertIsNotNone(status)

    def test_system_is_one_to_one_relationship(self) -> None:
        """Verify system field is OneToOneField"""
        field = TrigInvasion._meta.get_field("system")
        self.assertEqual(field.__class__.__name__, "OneToOneField")
        self.assertTrue(field.primary_key)
