# 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.authorization.models import (
    AuthorizationCheck,
    AuthorizationPermission,
    AuthorizationResource,
    GroupRoleAssignment,
    GroupRoleAssignmentList,
    GroupRoleAssignmentResource,
    ListMetadata,
    Permission,
    ReplaceGroupRoleAssignmentEntry,
    Role,
    RoleList,
    SlimRole,
    UserRoleAssignment,
    UserRoleAssignmentResource,
    UserRoleAssignmentSource,
)


class TestModelRoundTrip:
    def test_replace_group_role_assignment_entry_round_trip(self):
        data = load_fixture("replace_group_role_assignment_entry.json")
        instance = ReplaceGroupRoleAssignmentEntry.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = ReplaceGroupRoleAssignmentEntry.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_replace_group_role_assignment_entry_minimal_payload(self):
        data = {"role_slug": "admin"}
        instance = ReplaceGroupRoleAssignmentEntry.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["role_slug"] == data["role_slug"]

    def test_replace_group_role_assignment_entry_omits_absent_optional_non_nullable_fields(
        self,
    ):
        data = {"role_slug": "admin"}
        instance = ReplaceGroupRoleAssignmentEntry.from_dict(data)
        serialized = instance.to_dict()
        assert "resource_id" not in serialized
        assert "resource_external_id" not in serialized
        assert "resource_type_slug" not in serialized

    def test_list_metadata_round_trip(self):
        data = load_fixture("list_metadata.json")
        instance = ListMetadata.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = ListMetadata.from_dict(serialized)
        assert restored.to_dict() == serialized

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

    def test_list_metadata_preserves_nullable_fields(self):
        data = {"after": None, "before": None}
        instance = ListMetadata.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["after"] is None
        assert serialized["before"] is None

    def test_authorization_check_round_trip(self):
        data = load_fixture("authorization_check.json")
        instance = AuthorizationCheck.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = AuthorizationCheck.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_authorization_check_minimal_payload(self):
        data = {"authorized": True}
        instance = AuthorizationCheck.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["authorized"] == data["authorized"]

    def test_authorization_resource_round_trip(self):
        data = load_fixture("authorization_resource.json")
        instance = AuthorizationResource.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = AuthorizationResource.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_authorization_resource_minimal_payload(self):
        data = {
            "object": "authorization_resource",
            "name": "Website Redesign",
            "description": None,
            "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT",
            "parent_resource_id": None,
            "id": "authz_resource_01HXYZ123456789ABCDEFGH",
            "external_id": "proj-456",
            "resource_type_slug": "project",
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = AuthorizationResource.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["name"] == data["name"]
        assert serialized["description"] == data["description"]
        assert serialized["organization_id"] == data["organization_id"]
        assert serialized["parent_resource_id"] == data["parent_resource_id"]
        assert serialized["id"] == data["id"]
        assert serialized["external_id"] == data["external_id"]
        assert serialized["resource_type_slug"] == data["resource_type_slug"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]

    def test_authorization_resource_preserves_nullable_fields(self):
        data = {
            "object": "authorization_resource",
            "name": "Website Redesign",
            "description": None,
            "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT",
            "parent_resource_id": None,
            "id": "authz_resource_01HXYZ123456789ABCDEFGH",
            "external_id": "proj-456",
            "resource_type_slug": "project",
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = AuthorizationResource.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["description"] is None
        assert serialized["parent_resource_id"] is None

    def test_authorization_permission_round_trip(self):
        data = load_fixture("authorization_permission.json")
        instance = AuthorizationPermission.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = AuthorizationPermission.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_authorization_permission_minimal_payload(self):
        data = {
            "object": "permission",
            "id": "perm_01HXYZ123456789ABCDEFGHIJ",
            "slug": "documents:read",
            "name": "View Documents",
            "description": None,
            "system": False,
            "resource_type_slug": "workspace",
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = AuthorizationPermission.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["id"] == data["id"]
        assert serialized["slug"] == data["slug"]
        assert serialized["name"] == data["name"]
        assert serialized["description"] == data["description"]
        assert serialized["system"] == data["system"]
        assert serialized["resource_type_slug"] == data["resource_type_slug"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]

    def test_authorization_permission_preserves_nullable_fields(self):
        data = {
            "object": "permission",
            "id": "perm_01HXYZ123456789ABCDEFGHIJ",
            "slug": "documents:read",
            "name": "View Documents",
            "description": None,
            "system": False,
            "resource_type_slug": "workspace",
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = AuthorizationPermission.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["description"] is None

    def test_slim_role_round_trip(self):
        data = load_fixture("slim_role.json")
        instance = SlimRole.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = SlimRole.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_slim_role_minimal_payload(self):
        data = {"slug": "admin"}
        instance = SlimRole.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["slug"] == data["slug"]

    def test_group_role_assignment_round_trip(self):
        data = load_fixture("group_role_assignment.json")
        instance = GroupRoleAssignment.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = GroupRoleAssignment.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_group_role_assignment_minimal_payload(self):
        data = {
            "object": "group_role_assignment",
            "id": "gra_01HXYZ123456789ABCDEFGH",
            "group_id": "group_01HXYZ123456789ABCDEFGHIJ",
            "role": {"slug": "admin"},
            "resource": {
                "id": "authz_resource_01HXYZ123456789ABCDEFGH",
                "external_id": "proj-456",
                "resource_type_slug": "project",
            },
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = GroupRoleAssignment.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["id"] == data["id"]
        assert serialized["group_id"] == data["group_id"]
        assert serialized["role"] == data["role"]
        assert serialized["resource"] == data["resource"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]

    def test_group_role_assignment_list_round_trip(self):
        data = load_fixture("group_role_assignment_list.json")
        instance = GroupRoleAssignmentList.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = GroupRoleAssignmentList.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_group_role_assignment_list_minimal_payload(self):
        data = {
            "object": "list",
            "data": [
                {
                    "object": "group_role_assignment",
                    "id": "gra_01HXYZ123456789ABCDEFGH",
                    "group_id": "group_01HXYZ123456789ABCDEFGHIJ",
                    "role": {"slug": "admin"},
                    "resource": {
                        "id": "authz_resource_01HXYZ123456789ABCDEFGH",
                        "external_id": "proj-456",
                        "resource_type_slug": "project",
                    },
                    "created_at": "2026-01-15T12:00:00.000Z",
                    "updated_at": "2026-01-15T12:00:00.000Z",
                }
            ],
            "list_metadata": {
                "after": "b21f3a8c-7e4d-4b1a-9c5e-2d8f6a7b3c4e",
                "before": "a10e2b7d-6c3f-4a2b-8d1e-3f9a5b8c7d6e",
            },
        }
        instance = GroupRoleAssignmentList.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["data"] == data["data"]
        assert serialized["list_metadata"] == data["list_metadata"]

    def test_user_role_assignment_round_trip(self):
        data = load_fixture("user_role_assignment.json")
        instance = UserRoleAssignment.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = UserRoleAssignment.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_user_role_assignment_minimal_payload(self):
        data = {
            "object": "role_assignment",
            "id": "role_assignment_01HXYZ123456789ABCDEFGH",
            "organization_membership_id": "om_01HXYZ123456789ABCDEFGHIJ",
            "role": {"slug": "admin"},
            "resource": {
                "id": "authz_resource_01HXYZ123456789ABCDEFGH",
                "external_id": "proj-456",
                "resource_type_slug": "project",
            },
            "source": {"type": "direct", "group_role_assignment_id": None},
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = UserRoleAssignment.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["id"] == data["id"]
        assert (
            serialized["organization_membership_id"]
            == data["organization_membership_id"]
        )
        assert serialized["role"] == data["role"]
        assert serialized["resource"] == data["resource"]
        assert serialized["source"] == data["source"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]

    def test_role_round_trip(self):
        data = load_fixture("role.json")
        instance = Role.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = Role.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_role_minimal_payload(self):
        data = {
            "slug": "admin",
            "object": "role",
            "id": "role_01EHQMYV6MBK39QC5PZXHY59C3",
            "name": "Admin",
            "description": None,
            "type": "EnvironmentRole",
            "resource_type_slug": "organization",
            "permissions": ["posts:read", "posts:write"],
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = Role.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["slug"] == data["slug"]
        assert serialized["object"] == data["object"]
        assert serialized["id"] == data["id"]
        assert serialized["name"] == data["name"]
        assert serialized["description"] == data["description"]
        assert serialized["type"] == data["type"]
        assert serialized["resource_type_slug"] == data["resource_type_slug"]
        assert serialized["permissions"] == data["permissions"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]

    def test_role_preserves_nullable_fields(self):
        data = {
            "slug": "admin",
            "object": "role",
            "id": "role_01EHQMYV6MBK39QC5PZXHY59C3",
            "name": "Admin",
            "description": None,
            "type": "EnvironmentRole",
            "resource_type_slug": "organization",
            "permissions": ["posts:read", "posts:write"],
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = Role.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["description"] is None

    def test_role_round_trips_unknown_enum_values(self):
        data = {
            "slug": "admin",
            "object": "role",
            "id": "role_01EHQMYV6MBK39QC5PZXHY59C3",
            "name": "Admin",
            "description": "Can manage all resources",
            "type": "unexpected_role_type",
            "resource_type_slug": "organization",
            "permissions": ["posts:read", "posts:write"],
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = Role.from_dict(data)
        assert instance.to_dict() == data

    def test_role_list_round_trip(self):
        data = load_fixture("role_list.json")
        instance = RoleList.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = RoleList.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_role_list_minimal_payload(self):
        data = {
            "object": "list",
            "data": [
                {
                    "slug": "admin",
                    "object": "role",
                    "id": "role_01EHQMYV6MBK39QC5PZXHY59C3",
                    "name": "Admin",
                    "description": "Can manage all resources",
                    "type": "EnvironmentRole",
                    "resource_type_slug": "organization",
                    "permissions": ["posts:read", "posts:write"],
                    "created_at": "2026-01-15T12:00:00.000Z",
                    "updated_at": "2026-01-15T12:00:00.000Z",
                }
            ],
        }
        instance = RoleList.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["data"] == data["data"]

    def test_user_role_assignment_resource_round_trip(self):
        data = load_fixture("user_role_assignment_resource.json")
        instance = UserRoleAssignmentResource.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = UserRoleAssignmentResource.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_user_role_assignment_resource_minimal_payload(self):
        data = {
            "id": "authz_resource_01HXYZ123456789ABCDEFGH",
            "external_id": "proj-456",
            "resource_type_slug": "project",
        }
        instance = UserRoleAssignmentResource.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["id"] == data["id"]
        assert serialized["external_id"] == data["external_id"]
        assert serialized["resource_type_slug"] == data["resource_type_slug"]

    def test_user_role_assignment_source_round_trip(self):
        data = load_fixture("user_role_assignment_source.json")
        instance = UserRoleAssignmentSource.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = UserRoleAssignmentSource.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_user_role_assignment_source_minimal_payload(self):
        data = {"type": "direct", "group_role_assignment_id": None}
        instance = UserRoleAssignmentSource.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["type"] == data["type"]
        assert (
            serialized["group_role_assignment_id"] == data["group_role_assignment_id"]
        )

    def test_user_role_assignment_source_preserves_nullable_fields(self):
        data = {"type": "direct", "group_role_assignment_id": None}
        instance = UserRoleAssignmentSource.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["group_role_assignment_id"] is None

    def test_user_role_assignment_source_round_trips_unknown_enum_values(self):
        data = {
            "type": "unexpected_user_role_assignment_source_type",
            "group_role_assignment_id": None,
        }
        instance = UserRoleAssignmentSource.from_dict(data)
        assert instance.to_dict() == data

    def test_group_role_assignment_resource_round_trip(self):
        data = load_fixture("group_role_assignment_resource.json")
        instance = GroupRoleAssignmentResource.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = GroupRoleAssignmentResource.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_group_role_assignment_resource_minimal_payload(self):
        data = {
            "id": "authz_resource_01HXYZ123456789ABCDEFGH",
            "external_id": "proj-456",
            "resource_type_slug": "project",
        }
        instance = GroupRoleAssignmentResource.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["id"] == data["id"]
        assert serialized["external_id"] == data["external_id"]
        assert serialized["resource_type_slug"] == data["resource_type_slug"]

    def test_permission_round_trip(self):
        data = load_fixture("permission.json")
        instance = Permission.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = Permission.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_permission_minimal_payload(self):
        data = {
            "object": "permission",
            "id": "perm_01HXYZ123456789ABCDEFGHIJ",
            "slug": "documents:read",
            "name": "View Documents",
            "description": None,
            "system": False,
            "resource_type_slug": "document",
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = Permission.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["id"] == data["id"]
        assert serialized["slug"] == data["slug"]
        assert serialized["name"] == data["name"]
        assert serialized["description"] == data["description"]
        assert serialized["system"] == data["system"]
        assert serialized["resource_type_slug"] == data["resource_type_slug"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]

    def test_permission_preserves_nullable_fields(self):
        data = {
            "object": "permission",
            "id": "perm_01HXYZ123456789ABCDEFGHIJ",
            "slug": "documents:read",
            "name": "View Documents",
            "description": None,
            "system": False,
            "resource_type_slug": "document",
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = Permission.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["description"] is None
