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

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

from tests.generated_helpers import load_fixture
from workos.sso.models import (
    Connection,
    ConnectionDomain,
    Profile,
    SSOAuthorizeUrlResponse,
    SSOLogoutAuthorizeResponse,
    SSOTokenResponse,
    SSOTokenResponseOAuthToken,
)


class TestModelRoundTrip:
    def test_connection_round_trip(self):
        data = load_fixture("connection.json")
        instance = Connection.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = Connection.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_connection_minimal_payload(self):
        data = {
            "object": "connection",
            "id": "conn_01E4ZCR3C56J083X43JQXF3JK5",
            "connection_type": "OktaSAML",
            "name": "Foo Corp",
            "state": "active",
            "status": "linked",
            "domains": [
                {
                    "id": "org_domain_01EHZNVPK2QXHMVWCEDQEKY69A",
                    "object": "connection_domain",
                    "domain": "foo-corp.com",
                }
            ],
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = Connection.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["id"] == data["id"]
        assert serialized["connection_type"] == data["connection_type"]
        assert serialized["name"] == data["name"]
        assert serialized["state"] == data["state"]
        assert serialized["status"] == data["status"]
        assert serialized["domains"] == data["domains"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]

    def test_connection_omits_absent_optional_non_nullable_fields(self):
        data = {
            "object": "connection",
            "id": "conn_01E4ZCR3C56J083X43JQXF3JK5",
            "connection_type": "OktaSAML",
            "name": "Foo Corp",
            "state": "active",
            "status": "linked",
            "domains": [
                {
                    "id": "org_domain_01EHZNVPK2QXHMVWCEDQEKY69A",
                    "object": "connection_domain",
                    "domain": "foo-corp.com",
                }
            ],
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = Connection.from_dict(data)
        serialized = instance.to_dict()
        assert "organization_id" not in serialized

    def test_connection_round_trips_unknown_enum_values(self):
        data = {
            "object": "connection",
            "id": "conn_01E4ZCR3C56J083X43JQXF3JK5",
            "organization_id": "org_01EHWNCE74X7JSDV0X3SZ3KJNY",
            "connection_type": "unexpected_connection_connection_type",
            "name": "Foo Corp",
            "state": "active",
            "status": "linked",
            "domains": [
                {
                    "id": "org_domain_01EHZNVPK2QXHMVWCEDQEKY69A",
                    "object": "connection_domain",
                    "domain": "foo-corp.com",
                }
            ],
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = Connection.from_dict(data)
        assert instance.to_dict() == data

    def test_sso_authorize_url_response_round_trip(self):
        data = load_fixture("sso_authorize_url_response.json")
        instance = SSOAuthorizeUrlResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = SSOAuthorizeUrlResponse.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_sso_authorize_url_response_minimal_payload(self):
        data = {
            "url": "https://accounts.google.com/o/oauth2/v2/auth?client_id=example&redirect_uri=https%3A%2F%2Fapi.workos.com%2Fsso%2Fcallback&response_type=code&scope=openid%20profile%20email"
        }
        instance = SSOAuthorizeUrlResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["url"] == data["url"]

    def test_profile_round_trip(self):
        data = load_fixture("profile.json")
        instance = Profile.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = Profile.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_profile_minimal_payload(self):
        data = {
            "object": "profile",
            "id": "prof_01DMC79VCBZ0NY2099737PSVF1",
            "organization_id": None,
            "connection_id": "conn_01E4ZCR3C56J083X43JQXF3JK5",
            "connection_type": "OktaSAML",
            "idp_id": "103456789012345678901",
            "email": "todd@example.com",
            "first_name": None,
            "last_name": None,
            "name": None,
            "raw_attributes": {"key": {}},
        }
        instance = Profile.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["id"] == data["id"]
        assert serialized["organization_id"] == data["organization_id"]
        assert serialized["connection_id"] == data["connection_id"]
        assert serialized["connection_type"] == data["connection_type"]
        assert serialized["idp_id"] == data["idp_id"]
        assert serialized["email"] == data["email"]
        assert serialized["first_name"] == data["first_name"]
        assert serialized["last_name"] == data["last_name"]
        assert serialized["name"] == data["name"]
        assert serialized["raw_attributes"] == data["raw_attributes"]

    def test_profile_omits_absent_optional_non_nullable_fields(self):
        data = {
            "object": "profile",
            "id": "prof_01DMC79VCBZ0NY2099737PSVF1",
            "organization_id": "org_01EHQMYV6MBK39QC5PZXHY59C3",
            "connection_id": "conn_01E4ZCR3C56J083X43JQXF3JK5",
            "connection_type": "OktaSAML",
            "idp_id": "103456789012345678901",
            "email": "todd@example.com",
            "first_name": "Todd",
            "last_name": "Rundgren",
            "name": "Todd Rundgren",
            "role": {"slug": "admin"},
            "roles": [{"slug": "admin"}],
            "raw_attributes": {"key": {}},
        }
        instance = Profile.from_dict(data)
        serialized = instance.to_dict()
        assert "groups" not in serialized
        assert "custom_attributes" not in serialized

    def test_profile_preserves_nullable_fields(self):
        data = {
            "object": "profile",
            "id": "prof_01DMC79VCBZ0NY2099737PSVF1",
            "organization_id": None,
            "connection_id": "conn_01E4ZCR3C56J083X43JQXF3JK5",
            "connection_type": "OktaSAML",
            "idp_id": "103456789012345678901",
            "email": "todd@example.com",
            "first_name": None,
            "last_name": None,
            "name": None,
            "role": None,
            "roles": None,
            "groups": ["Engineering", "Admins"],
            "custom_attributes": {"key": {}},
            "raw_attributes": {"key": {}},
        }
        instance = Profile.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["organization_id"] is None
        assert serialized["first_name"] is None
        assert serialized["last_name"] is None
        assert serialized["name"] is None
        assert serialized["role"] is None
        assert serialized["roles"] is None

    def test_profile_round_trips_unknown_enum_values(self):
        data = {
            "object": "profile",
            "id": "prof_01DMC79VCBZ0NY2099737PSVF1",
            "organization_id": "org_01EHQMYV6MBK39QC5PZXHY59C3",
            "connection_id": "conn_01E4ZCR3C56J083X43JQXF3JK5",
            "connection_type": "unexpected_profile_connection_type",
            "idp_id": "103456789012345678901",
            "email": "todd@example.com",
            "first_name": "Todd",
            "last_name": "Rundgren",
            "name": "Todd Rundgren",
            "role": {"slug": "admin"},
            "roles": [{"slug": "admin"}],
            "groups": ["Engineering", "Admins"],
            "custom_attributes": {"key": {}},
            "raw_attributes": {"key": {}},
        }
        instance = Profile.from_dict(data)
        assert instance.to_dict() == data

    def test_sso_token_response_round_trip(self):
        data = load_fixture("sso_token_response.json")
        instance = SSOTokenResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = SSOTokenResponse.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_sso_token_response_minimal_payload(self):
        data = {
            "token_type": "Bearer",
            "access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6InNzby...",
            "expires_in": 600,
            "profile": {
                "object": "profile",
                "id": "prof_01DMC79VCBZ0NY2099737PSVF1",
                "organization_id": "org_01EHQMYV6MBK39QC5PZXHY59C3",
                "connection_id": "conn_01E4ZCR3C56J083X43JQXF3JK5",
                "connection_type": "OktaSAML",
                "idp_id": "103456789012345678901",
                "email": "todd@example.com",
                "first_name": "Todd",
                "last_name": "Rundgren",
                "name": "Todd Rundgren",
                "role": {"slug": "admin"},
                "roles": [{"slug": "admin"}],
                "groups": ["Engineering", "Admins"],
                "custom_attributes": {"key": {}},
                "raw_attributes": {"key": {}},
            },
        }
        instance = SSOTokenResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["token_type"] == data["token_type"]
        assert serialized["access_token"] == data["access_token"]
        assert serialized["expires_in"] == data["expires_in"]
        assert serialized["profile"] == data["profile"]

    def test_sso_token_response_omits_absent_optional_non_nullable_fields(self):
        data = {
            "token_type": "Bearer",
            "access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6InNzby...",
            "expires_in": 600,
            "profile": {
                "object": "profile",
                "id": "prof_01DMC79VCBZ0NY2099737PSVF1",
                "organization_id": "org_01EHQMYV6MBK39QC5PZXHY59C3",
                "connection_id": "conn_01E4ZCR3C56J083X43JQXF3JK5",
                "connection_type": "OktaSAML",
                "idp_id": "103456789012345678901",
                "email": "todd@example.com",
                "first_name": "Todd",
                "last_name": "Rundgren",
                "name": "Todd Rundgren",
                "role": {"slug": "admin"},
                "roles": [{"slug": "admin"}],
                "groups": ["Engineering", "Admins"],
                "custom_attributes": {"key": {}},
                "raw_attributes": {"key": {}},
            },
        }
        instance = SSOTokenResponse.from_dict(data)
        serialized = instance.to_dict()
        assert "oauth_tokens" not in serialized

    def test_sso_logout_authorize_response_round_trip(self):
        data = load_fixture("sso_logout_authorize_response.json")
        instance = SSOLogoutAuthorizeResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = SSOLogoutAuthorizeResponse.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_sso_logout_authorize_response_minimal_payload(self):
        data = {
            "logout_url": "https://auth.workos.com/sso/logout?token=eyJhbGciOiJSUzI1NiJ9",
            "logout_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwcm9maWxlX2lkIjoicHJvZl8wMUdXUTFHMEgyRk02QVNFRjBIUzEzSENXOS0zMDRrZzAzZyIsImV4cCI6IjE1MTYyMzkwMjIifQ.Wru9Qlnf5DpohtGCKhZU4cVOd3zpiu7QQ-XEX--5A_4",
        }
        instance = SSOLogoutAuthorizeResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["logout_url"] == data["logout_url"]
        assert serialized["logout_token"] == data["logout_token"]

    def test_sso_token_response_oauth_token_round_trip(self):
        data = load_fixture("sso_token_response_oauth_token.json")
        instance = SSOTokenResponseOAuthToken.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = SSOTokenResponseOAuthToken.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_sso_token_response_oauth_token_minimal_payload(self):
        data = {
            "provider": "GoogleOAuth",
            "refresh_token": "1//04g...",
            "access_token": "ya29.a0ARrdaM...",
            "expires_at": 1735141800,
            "scopes": ["profile", "email", "openid"],
        }
        instance = SSOTokenResponseOAuthToken.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["provider"] == data["provider"]
        assert serialized["refresh_token"] == data["refresh_token"]
        assert serialized["access_token"] == data["access_token"]
        assert serialized["expires_at"] == data["expires_at"]
        assert serialized["scopes"] == data["scopes"]

    def test_connection_domain_round_trip(self):
        data = load_fixture("connection_domain.json")
        instance = ConnectionDomain.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = ConnectionDomain.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_connection_domain_minimal_payload(self):
        data = {
            "id": "org_domain_01EHZNVPK2QXHMVWCEDQEKY69A",
            "object": "connection_domain",
            "domain": "foo-corp.com",
        }
        instance = ConnectionDomain.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["id"] == data["id"]
        assert serialized["object"] == data["object"]
        assert serialized["domain"] == data["domain"]
