# This file is auto-generated by oagen. Do not edit.

"""Model round-trip tests: from_dict(to_dict()) preserves data."""

import pytest

from tests.generated_helpers import load_fixture

from workos.common.models import ActionAuthenticationDenied
from workos.events.models import EventListListMetadata, EventSchema, EventSchemaUnknown


class TestModelRoundTrip:
    def test_event_list_list_metadata_round_trip(self):
        data = load_fixture("event_list_list_metadata.json")
        instance = EventListListMetadata.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = EventListListMetadata.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_event_list_list_metadata_minimal_payload(self):
        data = {"after": None}
        instance = EventListListMetadata.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["after"] == data["after"]

    def test_event_list_list_metadata_preserves_nullable_fields(self):
        data = {"after": None}
        instance = EventListListMetadata.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["after"] is None


class TestDiscriminatorDispatch:
    def test_event_schema_dispatches_known_variant(self):
        data = load_fixture("action_authentication_denied.json")
        result = EventSchema.from_dict(data)
        assert isinstance(result, ActionAuthenticationDenied)

    def test_event_schema_returns_unknown_for_unrecognized_type(self):
        data = load_fixture("action_authentication_denied.json")
        data = {**data, "event": "future.unrecognized.type"}
        result = EventSchema.from_dict(data)
        assert isinstance(result, EventSchemaUnknown)
        assert result.raw_data == data

    def test_event_schema_raises_on_missing_discriminator(self):
        data = load_fixture("action_authentication_denied.json")
        data = {k: v for k, v in data.items() if k != "event"}
        with pytest.raises(Exception):
            EventSchema.from_dict(data)

    def test_event_schema_raises_on_none_discriminator(self):
        data = load_fixture("action_authentication_denied.json")
        data = {**data, "event": None}
        with pytest.raises(Exception):
            EventSchema.from_dict(data)
