# 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.vault.models import (
    Actor,
    CreateDataKeyResponse,
    DecryptResponse,
    DeleteObjectResponse,
    ObjectMetadata,
    ObjectSummary,
    ObjectVersion,
    ObjectWithoutValue,
    VaultObject,
    VersionListResponse,
)


class TestModelRoundTrip:
    def test_actor_round_trip(self):
        data = load_fixture("actor.json")
        instance = Actor.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = Actor.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_actor_minimal_payload(self):
        data = {"id": "key_01K8ZYT4AWJ6XP0E0S8CTBHE3P", "name": "My API Key"}
        instance = Actor.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["id"] == data["id"]
        assert serialized["name"] == data["name"]

    def test_create_data_key_response_round_trip(self):
        data = load_fixture("create_data_key_response.json")
        instance = CreateDataKeyResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = CreateDataKeyResponse.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_create_data_key_response_minimal_payload(self):
        data = {
            "context": {"organization_id": "org_01K8ZYT4AWJ6XP0E0S8CTBHE3P"},
            "data_key": "DR9idtey9MpMrA1VRFrz30HB1yNgL2PoHZyjAkFeWgg=",
            "encrypted_keys": "V09TLkVLTS52MQBiZjUxY2NlYy03OGI0LTUyMDAtYjM4My0zNTczMGU3MWVmNjEBATEBJGJmNjVlMzI2LTQzYTAtNGIyMC04OGM0LTA3ZmYzZGU1NDM0YwF0YmY2NWUzMjYtNDNhMC00YjIwLTg4YzQtMDdmZjNkZTU0MzRj",
            "id": "bf51ccec-78b4-5200-b383-35730e71ef61",
        }
        instance = CreateDataKeyResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["context"] == data["context"]
        assert serialized["data_key"] == data["data_key"]
        assert serialized["encrypted_keys"] == data["encrypted_keys"]
        assert serialized["id"] == data["id"]

    def test_decrypt_response_round_trip(self):
        data = load_fixture("decrypt_response.json")
        instance = DecryptResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DecryptResponse.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_decrypt_response_minimal_payload(self):
        data = {
            "data_key": "DR9idtey9MpMrA1VRFrz30HB1yNgL2PoHZyjAkFeWgg=",
            "id": "bf51ccec-78b4-5200-b383-35730e71ef61",
        }
        instance = DecryptResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["data_key"] == data["data_key"]
        assert serialized["id"] == data["id"]

    def test_delete_object_response_round_trip(self):
        data = load_fixture("delete_object_response.json")
        instance = DeleteObjectResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DeleteObjectResponse.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_delete_object_response_minimal_payload(self):
        data = {"name": "my-secret", "success": True}
        instance = DeleteObjectResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["name"] == data["name"]
        assert serialized["success"] == data["success"]

    def test_vault_object_round_trip(self):
        data = load_fixture("vault_object.json")
        instance = VaultObject.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = VaultObject.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_vault_object_minimal_payload(self):
        data = {
            "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
            "metadata": {
                "context": {"organization_id": "org_01K8ZYT4AWJ6XP0E0S8CTBHE3P"},
                "environment_id": "environment_01K8ZYT4AWJ6XP0E0S8CTBHE3P",
                "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
                "key_id": "bf65e326-43a0-4b20-88c4-07ff3de5434c",
                "updated_at": "2024-06-15T10:30:00.000Z",
                "updated_by": {
                    "id": "key_01K8ZYT4AWJ6XP0E0S8CTBHE3P",
                    "name": "My API Key",
                },
                "version_id": "c3d4e5f6-7890-abcd-ef12-34567890abcd",
            },
            "name": "my-secret",
            "value": "s3cr3t-v4lu3",
        }
        instance = VaultObject.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["id"] == data["id"]
        assert serialized["metadata"] == data["metadata"]
        assert serialized["name"] == data["name"]
        assert serialized["value"] == data["value"]

    def test_object_metadata_round_trip(self):
        data = load_fixture("object_metadata.json")
        instance = ObjectMetadata.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = ObjectMetadata.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_object_metadata_minimal_payload(self):
        data = {
            "context": {"organization_id": "org_01K8ZYT4AWJ6XP0E0S8CTBHE3P"},
            "environment_id": "environment_01K8ZYT4AWJ6XP0E0S8CTBHE3P",
            "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
            "key_id": "bf65e326-43a0-4b20-88c4-07ff3de5434c",
            "updated_at": "2024-06-15T10:30:00.000Z",
            "updated_by": {
                "id": "key_01K8ZYT4AWJ6XP0E0S8CTBHE3P",
                "name": "My API Key",
            },
        }
        instance = ObjectMetadata.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["context"] == data["context"]
        assert serialized["environment_id"] == data["environment_id"]
        assert serialized["id"] == data["id"]
        assert serialized["key_id"] == data["key_id"]
        assert serialized["updated_at"] == data["updated_at"]
        assert serialized["updated_by"] == data["updated_by"]

    def test_object_metadata_preserves_nullable_fields(self):
        data = {
            "context": {"organization_id": "org_01K8ZYT4AWJ6XP0E0S8CTBHE3P"},
            "environment_id": "environment_01K8ZYT4AWJ6XP0E0S8CTBHE3P",
            "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
            "key_id": "bf65e326-43a0-4b20-88c4-07ff3de5434c",
            "updated_at": "2024-06-15T10:30:00.000Z",
            "updated_by": {
                "id": "key_01K8ZYT4AWJ6XP0E0S8CTBHE3P",
                "name": "My API Key",
            },
            "version_id": None,
        }
        instance = ObjectMetadata.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["version_id"] is None

    def test_object_summary_round_trip(self):
        data = load_fixture("object_summary.json")
        instance = ObjectSummary.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = ObjectSummary.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_object_summary_minimal_payload(self):
        data = {"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "name": "my-secret"}
        instance = ObjectSummary.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["id"] == data["id"]
        assert serialized["name"] == data["name"]

    def test_object_summary_preserves_nullable_fields(self):
        data = {
            "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
            "name": "my-secret",
            "updated_at": None,
        }
        instance = ObjectSummary.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["updated_at"] is None

    def test_object_version_round_trip(self):
        data = load_fixture("object_version.json")
        instance = ObjectVersion.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = ObjectVersion.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_object_version_minimal_payload(self):
        data = {
            "created_at": "2024-06-15T10:30:00.000Z",
            "current_version": True,
            "etag": "d41d8cd98f00b204e9800998ecf8427e",
            "id": "c3d4e5f6-7890-abcd-ef12-34567890abcd",
            "size": 256,
        }
        instance = ObjectVersion.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["created_at"] == data["created_at"]
        assert serialized["current_version"] == data["current_version"]
        assert serialized["etag"] == data["etag"]
        assert serialized["id"] == data["id"]
        assert serialized["size"] == data["size"]

    def test_object_without_value_round_trip(self):
        data = load_fixture("object_without_value.json")
        instance = ObjectWithoutValue.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = ObjectWithoutValue.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_object_without_value_minimal_payload(self):
        data = {
            "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
            "metadata": {
                "context": {"organization_id": "org_01K8ZYT4AWJ6XP0E0S8CTBHE3P"},
                "environment_id": "environment_01K8ZYT4AWJ6XP0E0S8CTBHE3P",
                "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
                "key_id": "bf65e326-43a0-4b20-88c4-07ff3de5434c",
                "updated_at": "2024-06-15T10:30:00.000Z",
                "updated_by": {
                    "id": "key_01K8ZYT4AWJ6XP0E0S8CTBHE3P",
                    "name": "My API Key",
                },
                "version_id": "c3d4e5f6-7890-abcd-ef12-34567890abcd",
            },
            "name": "my-secret",
        }
        instance = ObjectWithoutValue.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["id"] == data["id"]
        assert serialized["metadata"] == data["metadata"]
        assert serialized["name"] == data["name"]

    def test_version_list_response_round_trip(self):
        data = load_fixture("version_list_response.json")
        instance = VersionListResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = VersionListResponse.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_version_list_response_minimal_payload(self):
        data = {
            "data": [
                {
                    "created_at": "2024-06-15T10:30:00.000Z",
                    "current_version": True,
                    "etag": "d41d8cd98f00b204e9800998ecf8427e",
                    "id": "c3d4e5f6-7890-abcd-ef12-34567890abcd",
                    "size": 256,
                }
            ],
            "list_metadata": {
                "after": "b21f3a8c-7e4d-4b1a-9c5e-2d8f6a7b3c4e",
                "before": "a10e2b7d-6c3f-4a2b-8d1e-3f9a5b8c7d6e",
            },
        }
        instance = VersionListResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["data"] == data["data"]
        assert serialized["list_metadata"] == data["list_metadata"]
