# 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.groups.models import Group, UserOrganizationMembershipBaseListData


class TestModelRoundTrip:
    def test_group_round_trip(self):
        data = load_fixture("group.json")
        instance = Group.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = Group.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_group_minimal_payload(self):
        data = {
            "object": "group",
            "id": "group_01HXYZ123456789ABCDEFGHIJ",
            "organization_id": "org_01EHWNCE74X7JSDV0X3SZ3KJNY",
            "name": "Engineering",
            "description": None,
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = Group.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["name"] == data["name"]
        assert serialized["description"] == data["description"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]

    def test_group_preserves_nullable_fields(self):
        data = {
            "object": "group",
            "id": "group_01HXYZ123456789ABCDEFGHIJ",
            "organization_id": "org_01EHWNCE74X7JSDV0X3SZ3KJNY",
            "name": "Engineering",
            "description": None,
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = Group.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["description"] is None

    def test_user_organization_membership_base_list_data_round_trip(self):
        data = load_fixture("user_organization_membership_base_list_data.json")
        instance = UserOrganizationMembershipBaseListData.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = UserOrganizationMembershipBaseListData.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_user_organization_membership_base_list_data_minimal_payload(self):
        data = {
            "object": "organization_membership",
            "id": "om_01HXYZ123456789ABCDEFGHIJ",
            "user_id": "user_01E4ZCR3C56J083X43JQXF3JK5",
            "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT",
            "status": "active",
            "directory_managed": False,
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
            "user": {
                "object": "user",
                "id": "user_01E4ZCR3C56J083X43JQXF3JK5",
                "first_name": "Marcelina",
                "last_name": "Davis",
                "name": "Marcelina Davis",
                "profile_picture_url": "https://workoscdn.com/images/v1/123abc",
                "email": "marcelina.davis@example.com",
                "email_verified": True,
                "external_id": "f1ffa2b2-c20b-4d39-be5c-212726e11222",
                "metadata": {"timezone": "America/New_York"},
                "last_sign_in_at": "2025-06-25T19:07:33.000Z",
                "locale": "en-US",
                "created_at": "2026-01-15T12:00:00.000Z",
                "updated_at": "2026-01-15T12:00:00.000Z",
            },
        }
        instance = UserOrganizationMembershipBaseListData.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["id"] == data["id"]
        assert serialized["user_id"] == data["user_id"]
        assert serialized["organization_id"] == data["organization_id"]
        assert serialized["status"] == data["status"]
        assert serialized["directory_managed"] == data["directory_managed"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]
        assert serialized["user"] == data["user"]

    def test_user_organization_membership_base_list_data_omits_absent_optional_non_nullable_fields(
        self,
    ):
        data = {
            "object": "organization_membership",
            "id": "om_01HXYZ123456789ABCDEFGHIJ",
            "user_id": "user_01E4ZCR3C56J083X43JQXF3JK5",
            "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT",
            "status": "active",
            "directory_managed": False,
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
            "user": {
                "object": "user",
                "id": "user_01E4ZCR3C56J083X43JQXF3JK5",
                "first_name": "Marcelina",
                "last_name": "Davis",
                "name": "Marcelina Davis",
                "profile_picture_url": "https://workoscdn.com/images/v1/123abc",
                "email": "marcelina.davis@example.com",
                "email_verified": True,
                "external_id": "f1ffa2b2-c20b-4d39-be5c-212726e11222",
                "metadata": {"timezone": "America/New_York"},
                "last_sign_in_at": "2025-06-25T19:07:33.000Z",
                "locale": "en-US",
                "created_at": "2026-01-15T12:00:00.000Z",
                "updated_at": "2026-01-15T12:00:00.000Z",
            },
        }
        instance = UserOrganizationMembershipBaseListData.from_dict(data)
        serialized = instance.to_dict()
        assert "organization_name" not in serialized
        assert "custom_attributes" not in serialized

    def test_user_organization_membership_base_list_data_round_trips_unknown_enum_values(
        self,
    ):
        data = {
            "object": "organization_membership",
            "id": "om_01HXYZ123456789ABCDEFGHIJ",
            "user_id": "user_01E4ZCR3C56J083X43JQXF3JK5",
            "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT",
            "status": "unexpected_user_organization_membership_base_list_data_status",
            "directory_managed": False,
            "organization_name": "Acme Corp",
            "custom_attributes": {
                "department": "Engineering",
                "title": "Developer Experience Engineer",
                "location": "Brooklyn",
            },
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
            "user": {
                "object": "user",
                "id": "user_01E4ZCR3C56J083X43JQXF3JK5",
                "first_name": "Marcelina",
                "last_name": "Davis",
                "name": "Marcelina Davis",
                "profile_picture_url": "https://workoscdn.com/images/v1/123abc",
                "email": "marcelina.davis@example.com",
                "email_verified": True,
                "external_id": "f1ffa2b2-c20b-4d39-be5c-212726e11222",
                "metadata": {"timezone": "America/New_York"},
                "last_sign_in_at": "2025-06-25T19:07:33.000Z",
                "locale": "en-US",
                "created_at": "2026-01-15T12:00:00.000Z",
                "updated_at": "2026-01-15T12:00:00.000Z",
            },
        }
        instance = UserOrganizationMembershipBaseListData.from_dict(data)
        assert instance.to_dict() == data
