# 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 ConnectApplicationM2M
from workos.connect.models import (
    ApplicationCredentialsListItem,
    ConnectApplication,
    ConnectApplicationUnknown,
    ExternalAuthCompleteResponse,
    NewConnectApplicationSecret,
    RedirectUriInput,
    UserConsentOption,
    UserConsentOptionChoice,
    UserObject,
)


class TestModelRoundTrip:
    def test_user_object_round_trip(self):
        data = load_fixture("user_object.json")
        instance = UserObject.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = UserObject.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_user_object_minimal_payload(self):
        data = {"id": "user_12345", "email": "marcelina.davis@example.com"}
        instance = UserObject.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["id"] == data["id"]
        assert serialized["email"] == data["email"]

    def test_user_object_omits_absent_optional_non_nullable_fields(self):
        data = {"id": "user_12345", "email": "marcelina.davis@example.com"}
        instance = UserObject.from_dict(data)
        serialized = instance.to_dict()
        assert "first_name" not in serialized
        assert "last_name" not in serialized
        assert "name" not in serialized
        assert "metadata" not in serialized

    def test_user_consent_option_round_trip(self):
        data = load_fixture("user_consent_option.json")
        instance = UserConsentOption.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = UserConsentOption.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_user_consent_option_minimal_payload(self):
        data = {
            "claim": "tos_accepted",
            "type": "enum",
            "label": "Terms of Service",
            "choices": [
                {"value": "accepted", "label": "I accept the Terms of Service"}
            ],
        }
        instance = UserConsentOption.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["claim"] == data["claim"]
        assert serialized["type"] == data["type"]
        assert serialized["label"] == data["label"]
        assert serialized["choices"] == data["choices"]

    def test_redirect_uri_input_round_trip(self):
        data = load_fixture("redirect_uri_input.json")
        instance = RedirectUriInput.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = RedirectUriInput.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_redirect_uri_input_minimal_payload(self):
        data = {"uri": "https://example.com/callback"}
        instance = RedirectUriInput.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["uri"] == data["uri"]

    def test_redirect_uri_input_preserves_nullable_fields(self):
        data = {"uri": "https://example.com/callback", "default": None}
        instance = RedirectUriInput.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["default"] is None

    def test_external_auth_complete_response_round_trip(self):
        data = load_fixture("external_auth_complete_response.json")
        instance = ExternalAuthCompleteResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = ExternalAuthCompleteResponse.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_external_auth_complete_response_minimal_payload(self):
        data = {
            "redirect_uri": "https://your-authkit-domain.workos.com/oauth/authorize/complete?state=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdGF0ZSI6InJhbmRvbV9zdGF0ZV9zdHJpbmciLCJpYXQiOjE3NDI2MDQ4NTN9.abc123def456ghi789"
        }
        instance = ExternalAuthCompleteResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["redirect_uri"] == data["redirect_uri"]

    def test_new_connect_application_secret_round_trip(self):
        data = load_fixture("new_connect_application_secret.json")
        instance = NewConnectApplicationSecret.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = NewConnectApplicationSecret.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_new_connect_application_secret_minimal_payload(self):
        data = {
            "object": "connect_application_secret",
            "id": "secret_01J9Q2Z3X4Y5W6V7U8T9S0R1Q",
            "secret_hint": "abc123",
            "last_used_at": None,
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
            "secret": "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz",
        }
        instance = NewConnectApplicationSecret.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["id"] == data["id"]
        assert serialized["secret_hint"] == data["secret_hint"]
        assert serialized["last_used_at"] == data["last_used_at"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]
        assert serialized["secret"] == data["secret"]

    def test_new_connect_application_secret_preserves_nullable_fields(self):
        data = {
            "object": "connect_application_secret",
            "id": "secret_01J9Q2Z3X4Y5W6V7U8T9S0R1Q",
            "secret_hint": "abc123",
            "last_used_at": None,
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
            "secret": "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz",
        }
        instance = NewConnectApplicationSecret.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["last_used_at"] is None

    def test_user_consent_option_choice_round_trip(self):
        data = load_fixture("user_consent_option_choice.json")
        instance = UserConsentOptionChoice.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = UserConsentOptionChoice.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_user_consent_option_choice_minimal_payload(self):
        data = {}
        instance = UserConsentOptionChoice.from_dict(data)
        assert instance.to_dict() is not None

    def test_user_consent_option_choice_omits_absent_optional_non_nullable_fields(self):
        data = {}
        instance = UserConsentOptionChoice.from_dict(data)
        serialized = instance.to_dict()
        assert "value" not in serialized
        assert "label" not in serialized

    def test_application_credentials_list_item_round_trip(self):
        data = load_fixture("application_credentials_list_item.json")
        instance = ApplicationCredentialsListItem.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = ApplicationCredentialsListItem.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_application_credentials_list_item_minimal_payload(self):
        data = {
            "object": "connect_application_secret",
            "id": "secret_01J9Q2Z3X4Y5W6V7U8T9S0R1Q",
            "secret_hint": "abc123",
            "last_used_at": None,
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = ApplicationCredentialsListItem.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["id"] == data["id"]
        assert serialized["secret_hint"] == data["secret_hint"]
        assert serialized["last_used_at"] == data["last_used_at"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]

    def test_application_credentials_list_item_preserves_nullable_fields(self):
        data = {
            "object": "connect_application_secret",
            "id": "secret_01J9Q2Z3X4Y5W6V7U8T9S0R1Q",
            "secret_hint": "abc123",
            "last_used_at": None,
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = ApplicationCredentialsListItem.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["last_used_at"] is None


class TestDiscriminatorDispatch:
    def test_connect_application_dispatches_known_variant(self):
        data = load_fixture("connect_application_m2m.json")
        result = ConnectApplication.from_dict(data)
        assert isinstance(result, ConnectApplicationM2M)

    def test_connect_application_returns_unknown_for_unrecognized_type(self):
        data = load_fixture("connect_application_m2m.json")
        data = {**data, "application_type": "future.unrecognized.type"}
        result = ConnectApplication.from_dict(data)
        assert isinstance(result, ConnectApplicationUnknown)
        assert result.raw_data == data

    def test_connect_application_raises_on_missing_discriminator(self):
        data = load_fixture("connect_application_m2m.json")
        data = {k: v for k, v in data.items() if k != "application_type"}
        with pytest.raises(Exception):
            ConnectApplication.from_dict(data)

    def test_connect_application_raises_on_none_discriminator(self):
        data = load_fixture("connect_application_m2m.json")
        data = {**data, "application_type": None}
        with pytest.raises(Exception):
            ConnectApplication.from_dict(data)
