# 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.api_keys.models import (
    ApiKey,
    ApiKeyOwner,
    ApiKeyValidationResponse,
    OrganizationApiKey,
    OrganizationApiKeyOwner,
    OrganizationApiKeyWithValue,
    OrganizationApiKeyWithValueOwner,
)


class TestModelRoundTrip:
    def test_api_key_round_trip(self):
        data = load_fixture("api_key.json")
        instance = ApiKey.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = ApiKey.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_api_key_minimal_payload(self):
        data = {
            "object": "api_key",
            "id": "api_key_01EHZNVPK3SFK441A1RGBFSHRT",
            "owner": {"type": "organization", "id": "org_01EHZNVPK3SFK441A1RGBFSHRT"},
            "name": "Production API Key",
            "obfuscated_value": "sk_...3456",
            "last_used_at": None,
            "expires_at": None,
            "permissions": ["posts:read", "posts:write"],
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = ApiKey.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["id"] == data["id"]
        assert serialized["owner"] == data["owner"]
        assert serialized["name"] == data["name"]
        assert serialized["obfuscated_value"] == data["obfuscated_value"]
        assert serialized["last_used_at"] == data["last_used_at"]
        assert serialized["expires_at"] == data["expires_at"]
        assert serialized["permissions"] == data["permissions"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]

    def test_api_key_preserves_nullable_fields(self):
        data = {
            "object": "api_key",
            "id": "api_key_01EHZNVPK3SFK441A1RGBFSHRT",
            "owner": {"type": "organization", "id": "org_01EHZNVPK3SFK441A1RGBFSHRT"},
            "name": "Production API Key",
            "obfuscated_value": "sk_...3456",
            "last_used_at": None,
            "expires_at": None,
            "permissions": ["posts:read", "posts:write"],
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = ApiKey.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["last_used_at"] is None
        assert serialized["expires_at"] is None

    def test_api_key_validation_response_round_trip(self):
        data = load_fixture("api_key_validation_response.json")
        instance = ApiKeyValidationResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = ApiKeyValidationResponse.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_api_key_validation_response_minimal_payload(self):
        data = {"api_key": None}
        instance = ApiKeyValidationResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["api_key"] == data["api_key"]

    def test_api_key_validation_response_omits_absent_optional_non_nullable_fields(
        self,
    ):
        data = {
            "api_key": {
                "object": "api_key",
                "id": "api_key_01EHZNVPK3SFK441A1RGBFSHRT",
                "owner": {
                    "type": "organization",
                    "id": "org_01EHZNVPK3SFK441A1RGBFSHRT",
                },
                "name": "Production API Key",
                "obfuscated_value": "sk_...3456",
                "last_used_at": None,
                "expires_at": None,
                "permissions": ["posts:read", "posts:write"],
                "created_at": "2026-01-15T12:00:00.000Z",
                "updated_at": "2026-01-15T12:00:00.000Z",
            }
        }
        instance = ApiKeyValidationResponse.from_dict(data)
        serialized = instance.to_dict()
        assert "agent_registration_id" not in serialized

    def test_api_key_validation_response_preserves_nullable_fields(self):
        data = {
            "api_key": None,
            "agent_registration_id": "agent_reg_01EHZNVPK3SFK441A1RGBFSHRT",
        }
        instance = ApiKeyValidationResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["api_key"] is None

    def test_organization_api_key_round_trip(self):
        data = load_fixture("organization_api_key.json")
        instance = OrganizationApiKey.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = OrganizationApiKey.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_organization_api_key_minimal_payload(self):
        data = {
            "object": "api_key",
            "id": "api_key_01EHZNVPK3SFK441A1RGBFSHRT",
            "owner": {"type": "organization", "id": "org_01EHZNVPK3SFK441A1RGBFSHRT"},
            "name": "Production API Key",
            "obfuscated_value": "sk_...3456",
            "last_used_at": None,
            "expires_at": None,
            "permissions": ["posts:read", "posts:write"],
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = OrganizationApiKey.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["id"] == data["id"]
        assert serialized["owner"] == data["owner"]
        assert serialized["name"] == data["name"]
        assert serialized["obfuscated_value"] == data["obfuscated_value"]
        assert serialized["last_used_at"] == data["last_used_at"]
        assert serialized["expires_at"] == data["expires_at"]
        assert serialized["permissions"] == data["permissions"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]

    def test_organization_api_key_preserves_nullable_fields(self):
        data = {
            "object": "api_key",
            "id": "api_key_01EHZNVPK3SFK441A1RGBFSHRT",
            "owner": {"type": "organization", "id": "org_01EHZNVPK3SFK441A1RGBFSHRT"},
            "name": "Production API Key",
            "obfuscated_value": "sk_...3456",
            "last_used_at": None,
            "expires_at": None,
            "permissions": ["posts:read", "posts:write"],
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = OrganizationApiKey.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["last_used_at"] is None
        assert serialized["expires_at"] is None

    def test_organization_api_key_with_value_round_trip(self):
        data = load_fixture("organization_api_key_with_value.json")
        instance = OrganizationApiKeyWithValue.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = OrganizationApiKeyWithValue.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_organization_api_key_with_value_minimal_payload(self):
        data = {
            "object": "api_key",
            "id": "api_key_01EHZNVPK3SFK441A1RGBFSHRT",
            "owner": {"type": "organization", "id": "org_01EHZNVPK3SFK441A1RGBFSHRT"},
            "name": "Production API Key",
            "obfuscated_value": "sk_...3456",
            "last_used_at": None,
            "expires_at": None,
            "permissions": ["posts:read", "posts:write"],
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
            "value": "sk_abcdefghijklmnop123456",
        }
        instance = OrganizationApiKeyWithValue.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["id"] == data["id"]
        assert serialized["owner"] == data["owner"]
        assert serialized["name"] == data["name"]
        assert serialized["obfuscated_value"] == data["obfuscated_value"]
        assert serialized["last_used_at"] == data["last_used_at"]
        assert serialized["expires_at"] == data["expires_at"]
        assert serialized["permissions"] == data["permissions"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]
        assert serialized["value"] == data["value"]

    def test_organization_api_key_with_value_preserves_nullable_fields(self):
        data = {
            "object": "api_key",
            "id": "api_key_01EHZNVPK3SFK441A1RGBFSHRT",
            "owner": {"type": "organization", "id": "org_01EHZNVPK3SFK441A1RGBFSHRT"},
            "name": "Production API Key",
            "obfuscated_value": "sk_...3456",
            "last_used_at": None,
            "expires_at": None,
            "permissions": ["posts:read", "posts:write"],
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
            "value": "sk_abcdefghijklmnop123456",
        }
        instance = OrganizationApiKeyWithValue.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["last_used_at"] is None
        assert serialized["expires_at"] is None

    def test_organization_api_key_with_value_owner_round_trip(self):
        data = load_fixture("organization_api_key_with_value_owner.json")
        instance = OrganizationApiKeyWithValueOwner.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = OrganizationApiKeyWithValueOwner.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_organization_api_key_with_value_owner_minimal_payload(self):
        data = {"type": "organization", "id": "org_01EHZNVPK3SFK441A1RGBFSHRT"}
        instance = OrganizationApiKeyWithValueOwner.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["type"] == data["type"]
        assert serialized["id"] == data["id"]

    def test_organization_api_key_owner_round_trip(self):
        data = load_fixture("organization_api_key_owner.json")
        instance = OrganizationApiKeyOwner.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = OrganizationApiKeyOwner.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_organization_api_key_owner_minimal_payload(self):
        data = {"type": "organization", "id": "org_01EHZNVPK3SFK441A1RGBFSHRT"}
        instance = OrganizationApiKeyOwner.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["type"] == data["type"]
        assert serialized["id"] == data["id"]

    def test_api_key_owner_round_trip(self):
        data = load_fixture("api_key_owner.json")
        instance = ApiKeyOwner.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = ApiKeyOwner.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_api_key_owner_minimal_payload(self):
        data = {"type": "organization", "id": "org_01EHZNVPK3SFK441A1RGBFSHRT"}
        instance = ApiKeyOwner.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["type"] == data["type"]
        assert serialized["id"] == data["id"]
