# 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.pipes.models import (
    ApiKeyInstallation,
    ConnectedAccount,
    CustomProviderDefinition,
    DataIntegration,
    DataIntegrationAccessTokenResponse,
    DataIntegrationAccessTokenResponseAccessToken,
    DataIntegrationAuthorizeUrlResponse,
    DataIntegrationCredential,
    DataIntegrationCredentialsInput,
    DataIntegrationCredentialsResponse,
    DataIntegrationCredentialsResponseCredential,
    DataIntegrationCustomProvider,
    DataIntegrationInstallation,
    DataIntegrationsListResponse,
    DataIntegrationsListResponseData,
    DataIntegrationsListResponseDataConnectedAccount,
    UpdateCustomProviderDefinition,
)


class TestModelRoundTrip:
    def test_data_integration_credentials_input_round_trip(self):
        data = load_fixture("data_integration_credentials_input.json")
        instance = DataIntegrationCredentialsInput.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DataIntegrationCredentialsInput.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_data_integration_credentials_input_minimal_payload(self):
        data = {"type": "custom"}
        instance = DataIntegrationCredentialsInput.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["type"] == data["type"]

    def test_data_integration_credentials_input_omits_absent_optional_non_nullable_fields(
        self,
    ):
        data = {"type": "custom"}
        instance = DataIntegrationCredentialsInput.from_dict(data)
        serialized = instance.to_dict()
        assert "client_id" not in serialized
        assert "client_secret" not in serialized

    def test_data_integration_credentials_input_round_trips_unknown_enum_values(self):
        data = {
            "type": "unexpected_data_integration_credentials_input_type",
            "client_id": "Iv1.abc123",
            "client_secret": "secret_…",
        }
        instance = DataIntegrationCredentialsInput.from_dict(data)
        assert instance.to_dict() == data

    def test_api_key_installation_round_trip(self):
        data = load_fixture("api_key_installation.json")
        instance = ApiKeyInstallation.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = ApiKeyInstallation.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_api_key_installation_minimal_payload(self):
        data = {
            "secret": "sk-1234567890abcdef",
            "user_id": "user_01EHZNVPK3SFK441A1RGBFSHRT",
        }
        instance = ApiKeyInstallation.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["secret"] == data["secret"]
        assert serialized["user_id"] == data["user_id"]

    def test_api_key_installation_omits_absent_optional_non_nullable_fields(self):
        data = {
            "secret": "sk-1234567890abcdef",
            "user_id": "user_01EHZNVPK3SFK441A1RGBFSHRT",
        }
        instance = ApiKeyInstallation.from_dict(data)
        serialized = instance.to_dict()
        assert "organization_id" not in serialized

    def test_custom_provider_definition_round_trip(self):
        data = load_fixture("custom_provider_definition.json")
        instance = CustomProviderDefinition.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = CustomProviderDefinition.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_custom_provider_definition_minimal_payload(self):
        data = {
            "name": "My OAuth App",
            "authorization_url": "https://provider.example.com/oauth/authorize",
            "token_url": "https://provider.example.com/oauth/token",
        }
        instance = CustomProviderDefinition.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["name"] == data["name"]
        assert serialized["authorization_url"] == data["authorization_url"]
        assert serialized["token_url"] == data["token_url"]

    def test_custom_provider_definition_omits_absent_optional_non_nullable_fields(self):
        data = {
            "name": "My OAuth App",
            "authorization_url": "https://provider.example.com/oauth/authorize",
            "token_url": "https://provider.example.com/oauth/token",
            "refresh_token_url": "https://provider.example.com/oauth/token",
        }
        instance = CustomProviderDefinition.from_dict(data)
        serialized = instance.to_dict()
        assert "pkce_enabled" not in serialized
        assert "request_scope_separator" not in serialized
        assert "scopes_required" not in serialized
        assert "client_secret_required" not in serialized
        assert "additional_authorization_parameters" not in serialized
        assert "token_body_content_type" not in serialized
        assert "authenticate_via" not in serialized

    def test_custom_provider_definition_preserves_nullable_fields(self):
        data = {
            "name": "My OAuth App",
            "authorization_url": "https://provider.example.com/oauth/authorize",
            "token_url": "https://provider.example.com/oauth/token",
            "refresh_token_url": None,
            "pkce_enabled": True,
            "request_scope_separator": " ",
            "scopes_required": False,
            "client_secret_required": True,
            "additional_authorization_parameters": {"prompt": "consent"},
            "token_body_content_type": "application/x-www-form-urlencoded",
            "authenticate_via": "request_body",
        }
        instance = CustomProviderDefinition.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["refresh_token_url"] is None

    def test_custom_provider_definition_round_trips_unknown_enum_values(self):
        data = {
            "name": "My OAuth App",
            "authorization_url": "https://provider.example.com/oauth/authorize",
            "token_url": "https://provider.example.com/oauth/token",
            "refresh_token_url": "https://provider.example.com/oauth/token",
            "pkce_enabled": True,
            "request_scope_separator": " ",
            "scopes_required": False,
            "client_secret_required": True,
            "additional_authorization_parameters": {"prompt": "consent"},
            "token_body_content_type": "application/x-www-form-urlencoded",
            "authenticate_via": "unexpected_custom_provider_definition_authenticate_via",
        }
        instance = CustomProviderDefinition.from_dict(data)
        assert instance.to_dict() == data

    def test_update_custom_provider_definition_round_trip(self):
        data = load_fixture("update_custom_provider_definition.json")
        instance = UpdateCustomProviderDefinition.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = UpdateCustomProviderDefinition.from_dict(serialized)
        assert restored.to_dict() == serialized

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

    def test_update_custom_provider_definition_omits_absent_optional_non_nullable_fields(
        self,
    ):
        data = {"refresh_token_url": "https://provider.example.com/oauth/token"}
        instance = UpdateCustomProviderDefinition.from_dict(data)
        serialized = instance.to_dict()
        assert "name" not in serialized
        assert "authorization_url" not in serialized
        assert "token_url" not in serialized
        assert "pkce_enabled" not in serialized
        assert "request_scope_separator" not in serialized
        assert "scopes_required" not in serialized
        assert "client_secret_required" not in serialized
        assert "additional_authorization_parameters" not in serialized
        assert "token_body_content_type" not in serialized
        assert "authenticate_via" not in serialized

    def test_update_custom_provider_definition_preserves_nullable_fields(self):
        data = {
            "name": "My OAuth App",
            "authorization_url": "https://provider.example.com/oauth/authorize",
            "token_url": "https://provider.example.com/oauth/token",
            "refresh_token_url": None,
            "pkce_enabled": True,
            "request_scope_separator": " ",
            "scopes_required": False,
            "client_secret_required": True,
            "additional_authorization_parameters": {"prompt": "consent"},
            "token_body_content_type": "application/x-www-form-urlencoded",
            "authenticate_via": "request_body",
        }
        instance = UpdateCustomProviderDefinition.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["refresh_token_url"] is None

    def test_update_custom_provider_definition_round_trips_unknown_enum_values(self):
        data = {
            "name": "My OAuth App",
            "authorization_url": "https://provider.example.com/oauth/authorize",
            "token_url": "https://provider.example.com/oauth/token",
            "refresh_token_url": "https://provider.example.com/oauth/token",
            "pkce_enabled": True,
            "request_scope_separator": " ",
            "scopes_required": False,
            "client_secret_required": True,
            "additional_authorization_parameters": {"prompt": "consent"},
            "token_body_content_type": "application/x-www-form-urlencoded",
            "authenticate_via": "unexpected_update_custom_provider_definition_authenticate_via",
        }
        instance = UpdateCustomProviderDefinition.from_dict(data)
        assert instance.to_dict() == data

    def test_data_integration_round_trip(self):
        data = load_fixture("data_integration.json")
        instance = DataIntegration.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DataIntegration.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_data_integration_minimal_payload(self):
        data = {
            "object": "data_integration",
            "id": "data_integration_01EHZNVPK3SFK441A1RGBFSHRT",
            "slug": "github",
            "integration_type": "github",
            "description": None,
            "enabled": True,
            "state": "valid",
            "scopes": None,
            "redirect_uri": "https://api.workos.com/data-integrations/github/dik_01EHZNVPK3SFK441A1RGBFSHRT/callback",
            "auth_methods": ["oauth"],
            "credentials": {
                "type": "custom",
                "client_id": "Iv1.abc123",
                "redacted_client_secret": "6789",
            },
            "installation": None,
            "config": {"account_identifier": "acme-prod"},
            "custom_provider": None,
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = DataIntegration.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["id"] == data["id"]
        assert serialized["slug"] == data["slug"]
        assert serialized["integration_type"] == data["integration_type"]
        assert serialized["description"] == data["description"]
        assert serialized["enabled"] == data["enabled"]
        assert serialized["state"] == data["state"]
        assert serialized["scopes"] == data["scopes"]
        assert serialized["redirect_uri"] == data["redirect_uri"]
        assert serialized["auth_methods"] == data["auth_methods"]
        assert serialized["credentials"] == data["credentials"]
        assert serialized["installation"] == data["installation"]
        assert serialized["config"] == data["config"]
        assert serialized["custom_provider"] == data["custom_provider"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]

    def test_data_integration_preserves_nullable_fields(self):
        data = {
            "object": "data_integration",
            "id": "data_integration_01EHZNVPK3SFK441A1RGBFSHRT",
            "slug": "github",
            "integration_type": "github",
            "description": None,
            "enabled": True,
            "state": "valid",
            "scopes": None,
            "redirect_uri": "https://api.workos.com/data-integrations/github/dik_01EHZNVPK3SFK441A1RGBFSHRT/callback",
            "auth_methods": ["oauth"],
            "credentials": {
                "type": "custom",
                "client_id": "Iv1.abc123",
                "redacted_client_secret": "6789",
            },
            "installation": None,
            "config": {"account_identifier": "acme-prod"},
            "custom_provider": None,
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = DataIntegration.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["description"] is None
        assert serialized["scopes"] is None
        assert serialized["installation"] is None
        assert serialized["custom_provider"] is None

    def test_data_integration_round_trips_unknown_enum_values(self):
        data = {
            "object": "data_integration",
            "id": "data_integration_01EHZNVPK3SFK441A1RGBFSHRT",
            "slug": "github",
            "integration_type": "github",
            "description": "Production GitHub app",
            "enabled": True,
            "state": "unexpected_data_integration_state",
            "scopes": ["repo", "read:org"],
            "redirect_uri": "https://api.workos.com/data-integrations/github/dik_01EHZNVPK3SFK441A1RGBFSHRT/callback",
            "auth_methods": ["oauth"],
            "credentials": {
                "type": "custom",
                "client_id": "Iv1.abc123",
                "redacted_client_secret": "6789",
            },
            "installation": None,
            "config": {"account_identifier": "acme-prod"},
            "custom_provider": {
                "name": "My OAuth App",
                "authorization_url": "https://provider.example.com/oauth/authorize",
                "token_url": "https://provider.example.com/oauth/token",
                "refresh_token_url": "https://provider.example.com/oauth/token",
                "pkce_enabled": True,
                "request_scope_separator": " ",
                "scopes_required": False,
                "client_secret_required": True,
                "additional_authorization_parameters": {"prompt": "consent"},
                "token_body_content_type": "application/x-www-form-urlencoded",
                "authenticate_via": "request_body",
            },
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = DataIntegration.from_dict(data)
        assert instance.to_dict() == data

    def test_data_integration_authorize_url_response_round_trip(self):
        data = load_fixture("data_integration_authorize_url_response.json")
        instance = DataIntegrationAuthorizeUrlResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DataIntegrationAuthorizeUrlResponse.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_data_integration_authorize_url_response_minimal_payload(self):
        data = {
            "url": "https://api.workos.com/data-integrations/q2czJKmVAraSBg8xFpT7M9uR/authorize-redirect"
        }
        instance = DataIntegrationAuthorizeUrlResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["url"] == data["url"]

    def test_data_integration_access_token_response_round_trip(self):
        data = load_fixture("data_integration_access_token_response.json")
        instance = DataIntegrationAccessTokenResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DataIntegrationAccessTokenResponse.from_dict(serialized)
        assert restored.to_dict() == serialized

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

    def test_data_integration_access_token_response_omits_absent_optional_non_nullable_fields(
        self,
    ):
        data = {}
        instance = DataIntegrationAccessTokenResponse.from_dict(data)
        serialized = instance.to_dict()
        assert "active" not in serialized
        assert "access_token" not in serialized
        assert "error" not in serialized

    def test_data_integration_access_token_response_round_trips_unknown_enum_values(
        self,
    ):
        data = {
            "active": True,
            "access_token": {
                "object": "access_token",
                "access_token": "gho_16C7e42F292c6912E7710c838347Ae178B4a",
                "expires_at": "2025-12-31T23:59:59.000Z",
                "scopes": ["repo", "user:email"],
                "missing_scopes": [],
            },
            "error": "unexpected_data_integration_access_token_response_error",
        }
        instance = DataIntegrationAccessTokenResponse.from_dict(data)
        assert instance.to_dict() == data

    def test_data_integration_credentials_response_round_trip(self):
        data = load_fixture("data_integration_credentials_response.json")
        instance = DataIntegrationCredentialsResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DataIntegrationCredentialsResponse.from_dict(serialized)
        assert restored.to_dict() == serialized

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

    def test_data_integration_credentials_response_omits_absent_optional_non_nullable_fields(
        self,
    ):
        data = {}
        instance = DataIntegrationCredentialsResponse.from_dict(data)
        serialized = instance.to_dict()
        assert "active" not in serialized
        assert "credential" not in serialized
        assert "error" not in serialized

    def test_data_integration_credentials_response_round_trips_unknown_enum_values(
        self,
    ):
        data = {
            "active": True,
            "credential": {
                "object": "credential",
                "auth_method": "oauth",
                "value": "gho_16C7e42F292c6912E7710c838347Ae178B4a",
                "expires_at": "2025-12-31T23:59:59.000Z",
                "scopes": ["repo", "user:email"],
                "missing_scopes": [],
            },
            "error": "unexpected_data_integration_credentials_response_error",
        }
        instance = DataIntegrationCredentialsResponse.from_dict(data)
        assert instance.to_dict() == data

    def test_connected_account_round_trip(self):
        data = load_fixture("connected_account.json")
        instance = ConnectedAccount.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = ConnectedAccount.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_connected_account_minimal_payload(self):
        data = {
            "object": "connected_account",
            "id": "data_installation_01EHZNVPK3SFK441A1RGBFSHRT",
            "user_id": None,
            "organization_id": None,
            "scopes": ["repo", "user:email"],
            "state": "connected",
            "created_at": "2024-01-16T14:20:00.000Z",
            "updated_at": "2024-01-16T14:20:00.000Z",
        }
        instance = ConnectedAccount.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["scopes"] == data["scopes"]
        assert serialized["state"] == data["state"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]

    def test_connected_account_omits_absent_optional_non_nullable_fields(self):
        data = {
            "object": "connected_account",
            "id": "data_installation_01EHZNVPK3SFK441A1RGBFSHRT",
            "user_id": "user_01EHZNVPK3SFK441A1RGBFSHRT",
            "organization_id": None,
            "scopes": ["repo", "user:email"],
            "api_key_last_4": None,
            "state": "connected",
            "created_at": "2024-01-16T14:20:00.000Z",
            "updated_at": "2024-01-16T14:20:00.000Z",
        }
        instance = ConnectedAccount.from_dict(data)
        serialized = instance.to_dict()
        assert "auth_method" not in serialized

    def test_connected_account_preserves_nullable_fields(self):
        data = {
            "object": "connected_account",
            "id": "data_installation_01EHZNVPK3SFK441A1RGBFSHRT",
            "user_id": None,
            "organization_id": None,
            "scopes": ["repo", "user:email"],
            "auth_method": "oauth",
            "api_key_last_4": None,
            "state": "connected",
            "created_at": "2024-01-16T14:20:00.000Z",
            "updated_at": "2024-01-16T14:20:00.000Z",
        }
        instance = ConnectedAccount.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["user_id"] is None
        assert serialized["organization_id"] is None
        assert serialized["api_key_last_4"] is None

    def test_connected_account_round_trips_unknown_enum_values(self):
        data = {
            "object": "connected_account",
            "id": "data_installation_01EHZNVPK3SFK441A1RGBFSHRT",
            "user_id": "user_01EHZNVPK3SFK441A1RGBFSHRT",
            "organization_id": None,
            "scopes": ["repo", "user:email"],
            "auth_method": "unexpected_connected_account_auth_method",
            "api_key_last_4": None,
            "state": "connected",
            "created_at": "2024-01-16T14:20:00.000Z",
            "updated_at": "2024-01-16T14:20:00.000Z",
        }
        instance = ConnectedAccount.from_dict(data)
        assert instance.to_dict() == data

    def test_data_integrations_list_response_round_trip(self):
        data = load_fixture("data_integrations_list_response.json")
        instance = DataIntegrationsListResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DataIntegrationsListResponse.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_data_integrations_list_response_minimal_payload(self):
        data = {
            "object": "list",
            "data": [
                {
                    "object": "data_provider",
                    "id": "data_integration_01EHZNVPK3SFK441A1RGBFSHRT",
                    "name": "GitHub",
                    "description": "Connect your GitHub account to access repositories.",
                    "slug": "github",
                    "integration_type": "github",
                    "credentials_type": "oauth2",
                    "scopes": ["repo", "user:email"],
                    "auth_methods": ["oauth"],
                    "ownership": "userland_user",
                    "created_at": "2024-01-15T10:30:00.000Z",
                    "updated_at": "2024-01-15T10:30:00.000Z",
                    "connected_account": {
                        "object": "connected_account",
                        "id": "data_installation_01EHZNVPK3SFK441A1RGBFSHRT",
                        "user_id": "user_01EHZNVPK3SFK441A1RGBFSHRT",
                        "organization_id": None,
                        "scopes": ["repo", "user:email"],
                        "auth_method": "oauth",
                        "api_key_last_4": None,
                        "state": "connected",
                        "created_at": "2024-01-16T14:20:00.000Z",
                        "updated_at": "2024-01-16T14:20:00.000Z",
                        "userlandUserId": "test_userlandUserId",
                    },
                }
            ],
        }
        instance = DataIntegrationsListResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["data"] == data["data"]

    def test_data_integrations_list_response_data_round_trip(self):
        data = load_fixture("data_integrations_list_response_data.json")
        instance = DataIntegrationsListResponseData.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DataIntegrationsListResponseData.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_data_integrations_list_response_data_minimal_payload(self):
        data = {
            "object": "data_provider",
            "id": "data_integration_01EHZNVPK3SFK441A1RGBFSHRT",
            "name": "GitHub",
            "description": None,
            "slug": "github",
            "integration_type": "github",
            "credentials_type": "oauth2",
            "scopes": None,
            "ownership": "userland_user",
            "created_at": "2024-01-15T10:30:00.000Z",
            "updated_at": "2024-01-15T10:30:00.000Z",
            "connected_account": None,
        }
        instance = DataIntegrationsListResponseData.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["id"] == data["id"]
        assert serialized["name"] == data["name"]
        assert serialized["description"] == data["description"]
        assert serialized["slug"] == data["slug"]
        assert serialized["integration_type"] == data["integration_type"]
        assert serialized["credentials_type"] == data["credentials_type"]
        assert serialized["scopes"] == data["scopes"]
        assert serialized["ownership"] == data["ownership"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]
        assert serialized["connected_account"] == data["connected_account"]

    def test_data_integrations_list_response_data_omits_absent_optional_non_nullable_fields(
        self,
    ):
        data = {
            "object": "data_provider",
            "id": "data_integration_01EHZNVPK3SFK441A1RGBFSHRT",
            "name": "GitHub",
            "description": "Connect your GitHub account to access repositories.",
            "slug": "github",
            "integration_type": "github",
            "credentials_type": "oauth2",
            "scopes": ["repo", "user:email"],
            "ownership": "userland_user",
            "created_at": "2024-01-15T10:30:00.000Z",
            "updated_at": "2024-01-15T10:30:00.000Z",
            "connected_account": {
                "object": "connected_account",
                "id": "data_installation_01EHZNVPK3SFK441A1RGBFSHRT",
                "user_id": "user_01EHZNVPK3SFK441A1RGBFSHRT",
                "organization_id": None,
                "scopes": ["repo", "user:email"],
                "auth_method": "oauth",
                "api_key_last_4": None,
                "state": "connected",
                "created_at": "2024-01-16T14:20:00.000Z",
                "updated_at": "2024-01-16T14:20:00.000Z",
                "userlandUserId": "test_userlandUserId",
            },
        }
        instance = DataIntegrationsListResponseData.from_dict(data)
        serialized = instance.to_dict()
        assert "auth_methods" not in serialized

    def test_data_integrations_list_response_data_preserves_nullable_fields(self):
        data = {
            "object": "data_provider",
            "id": "data_integration_01EHZNVPK3SFK441A1RGBFSHRT",
            "name": "GitHub",
            "description": None,
            "slug": "github",
            "integration_type": "github",
            "credentials_type": "oauth2",
            "scopes": None,
            "auth_methods": ["oauth"],
            "ownership": "userland_user",
            "created_at": "2024-01-15T10:30:00.000Z",
            "updated_at": "2024-01-15T10:30:00.000Z",
            "connected_account": None,
        }
        instance = DataIntegrationsListResponseData.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["description"] is None
        assert serialized["scopes"] is None
        assert serialized["connected_account"] is None

    def test_data_integrations_list_response_data_round_trips_unknown_enum_values(self):
        data = {
            "object": "data_provider",
            "id": "data_integration_01EHZNVPK3SFK441A1RGBFSHRT",
            "name": "GitHub",
            "description": "Connect your GitHub account to access repositories.",
            "slug": "github",
            "integration_type": "github",
            "credentials_type": "oauth2",
            "scopes": ["repo", "user:email"],
            "auth_methods": ["oauth"],
            "ownership": "unexpected_data_integrations_list_response_data_ownership",
            "created_at": "2024-01-15T10:30:00.000Z",
            "updated_at": "2024-01-15T10:30:00.000Z",
            "connected_account": {
                "object": "connected_account",
                "id": "data_installation_01EHZNVPK3SFK441A1RGBFSHRT",
                "user_id": "user_01EHZNVPK3SFK441A1RGBFSHRT",
                "organization_id": None,
                "scopes": ["repo", "user:email"],
                "auth_method": "oauth",
                "api_key_last_4": None,
                "state": "connected",
                "created_at": "2024-01-16T14:20:00.000Z",
                "updated_at": "2024-01-16T14:20:00.000Z",
                "userlandUserId": "test_userlandUserId",
            },
        }
        instance = DataIntegrationsListResponseData.from_dict(data)
        assert instance.to_dict() == data

    def test_data_integration_credentials_response_credential_round_trip(self):
        data = load_fixture("data_integration_credentials_response_credential.json")
        instance = DataIntegrationCredentialsResponseCredential.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DataIntegrationCredentialsResponseCredential.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_data_integration_credentials_response_credential_minimal_payload(self):
        data = {
            "object": "credential",
            "auth_method": "oauth",
            "value": "gho_16C7e42F292c6912E7710c838347Ae178B4a",
            "expires_at": None,
            "scopes": ["repo", "user:email"],
            "missing_scopes": [],
        }
        instance = DataIntegrationCredentialsResponseCredential.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["auth_method"] == data["auth_method"]
        assert serialized["value"] == data["value"]
        assert serialized["expires_at"] == data["expires_at"]
        assert serialized["scopes"] == data["scopes"]
        assert serialized["missing_scopes"] == data["missing_scopes"]

    def test_data_integration_credentials_response_credential_preserves_nullable_fields(
        self,
    ):
        data = {
            "object": "credential",
            "auth_method": "oauth",
            "value": "gho_16C7e42F292c6912E7710c838347Ae178B4a",
            "expires_at": None,
            "scopes": ["repo", "user:email"],
            "missing_scopes": [],
        }
        instance = DataIntegrationCredentialsResponseCredential.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["expires_at"] is None

    def test_data_integration_access_token_response_access_token_round_trip(self):
        data = load_fixture("data_integration_access_token_response_access_token.json")
        instance = DataIntegrationAccessTokenResponseAccessToken.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DataIntegrationAccessTokenResponseAccessToken.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_data_integration_access_token_response_access_token_minimal_payload(self):
        data = {
            "object": "access_token",
            "access_token": "gho_16C7e42F292c6912E7710c838347Ae178B4a",
            "expires_at": None,
            "scopes": ["repo", "user:email"],
            "missing_scopes": [],
        }
        instance = DataIntegrationAccessTokenResponseAccessToken.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["access_token"] == data["access_token"]
        assert serialized["expires_at"] == data["expires_at"]
        assert serialized["scopes"] == data["scopes"]
        assert serialized["missing_scopes"] == data["missing_scopes"]

    def test_data_integration_access_token_response_access_token_preserves_nullable_fields(
        self,
    ):
        data = {
            "object": "access_token",
            "access_token": "gho_16C7e42F292c6912E7710c838347Ae178B4a",
            "expires_at": None,
            "scopes": ["repo", "user:email"],
            "missing_scopes": [],
        }
        instance = DataIntegrationAccessTokenResponseAccessToken.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["expires_at"] is None

    def test_data_integration_credential_round_trip(self):
        data = load_fixture("data_integration_credential.json")
        instance = DataIntegrationCredential.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DataIntegrationCredential.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_data_integration_credential_minimal_payload(self):
        data = {"type": "custom", "client_id": None, "redacted_client_secret": None}
        instance = DataIntegrationCredential.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["type"] == data["type"]
        assert serialized["client_id"] == data["client_id"]
        assert serialized["redacted_client_secret"] == data["redacted_client_secret"]

    def test_data_integration_credential_preserves_nullable_fields(self):
        data = {"type": "custom", "client_id": None, "redacted_client_secret": None}
        instance = DataIntegrationCredential.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["client_id"] is None
        assert serialized["redacted_client_secret"] is None

    def test_data_integration_credential_round_trips_unknown_enum_values(self):
        data = {
            "type": "unexpected_data_integration_credential_type",
            "client_id": "Iv1.abc123",
            "redacted_client_secret": "6789",
        }
        instance = DataIntegrationCredential.from_dict(data)
        assert instance.to_dict() == data

    def test_data_integration_installation_round_trip(self):
        data = load_fixture("data_integration_installation.json")
        instance = DataIntegrationInstallation.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DataIntegrationInstallation.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_data_integration_installation_minimal_payload(self):
        data = {
            "id": "data_installation_01EHZNVPK3SFK441A1RGBFSHRT",
            "user_id": "user_01EHZNVPK3SFK441A1RGBFSHRT",
            "organization_id": None,
            "api_key_last_4": None,
        }
        instance = DataIntegrationInstallation.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["id"] == data["id"]
        assert serialized["user_id"] == data["user_id"]
        assert serialized["organization_id"] == data["organization_id"]
        assert serialized["api_key_last_4"] == data["api_key_last_4"]

    def test_data_integration_installation_preserves_nullable_fields(self):
        data = {
            "id": "data_installation_01EHZNVPK3SFK441A1RGBFSHRT",
            "user_id": "user_01EHZNVPK3SFK441A1RGBFSHRT",
            "organization_id": None,
            "api_key_last_4": None,
        }
        instance = DataIntegrationInstallation.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["organization_id"] is None
        assert serialized["api_key_last_4"] is None

    def test_data_integration_custom_provider_round_trip(self):
        data = load_fixture("data_integration_custom_provider.json")
        instance = DataIntegrationCustomProvider.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DataIntegrationCustomProvider.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_data_integration_custom_provider_minimal_payload(self):
        data = {
            "name": "My OAuth App",
            "authorization_url": None,
            "token_url": None,
            "refresh_token_url": None,
            "pkce_enabled": True,
            "request_scope_separator": " ",
            "scopes_required": False,
            "client_secret_required": True,
            "additional_authorization_parameters": {"prompt": "consent"},
            "token_body_content_type": "application/x-www-form-urlencoded",
            "authenticate_via": "request_body",
        }
        instance = DataIntegrationCustomProvider.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["name"] == data["name"]
        assert serialized["authorization_url"] == data["authorization_url"]
        assert serialized["token_url"] == data["token_url"]
        assert serialized["refresh_token_url"] == data["refresh_token_url"]
        assert serialized["pkce_enabled"] == data["pkce_enabled"]
        assert serialized["request_scope_separator"] == data["request_scope_separator"]
        assert serialized["scopes_required"] == data["scopes_required"]
        assert serialized["client_secret_required"] == data["client_secret_required"]
        assert (
            serialized["additional_authorization_parameters"]
            == data["additional_authorization_parameters"]
        )
        assert serialized["token_body_content_type"] == data["token_body_content_type"]
        assert serialized["authenticate_via"] == data["authenticate_via"]

    def test_data_integration_custom_provider_preserves_nullable_fields(self):
        data = {
            "name": "My OAuth App",
            "authorization_url": None,
            "token_url": None,
            "refresh_token_url": None,
            "pkce_enabled": True,
            "request_scope_separator": " ",
            "scopes_required": False,
            "client_secret_required": True,
            "additional_authorization_parameters": {"prompt": "consent"},
            "token_body_content_type": "application/x-www-form-urlencoded",
            "authenticate_via": "request_body",
        }
        instance = DataIntegrationCustomProvider.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["authorization_url"] is None
        assert serialized["token_url"] is None
        assert serialized["refresh_token_url"] is None

    def test_data_integration_custom_provider_round_trips_unknown_enum_values(self):
        data = {
            "name": "My OAuth App",
            "authorization_url": "https://provider.example.com/oauth/authorize",
            "token_url": "https://provider.example.com/oauth/token",
            "refresh_token_url": "https://provider.example.com/oauth/token",
            "pkce_enabled": True,
            "request_scope_separator": " ",
            "scopes_required": False,
            "client_secret_required": True,
            "additional_authorization_parameters": {"prompt": "consent"},
            "token_body_content_type": "application/x-www-form-urlencoded",
            "authenticate_via": "unexpected_data_integration_custom_provider_authenticate_via",
        }
        instance = DataIntegrationCustomProvider.from_dict(data)
        assert instance.to_dict() == data

    def test_data_integrations_list_response_data_connected_account_round_trip(self):
        data = load_fixture(
            "data_integrations_list_response_data_connected_account.json"
        )
        instance = DataIntegrationsListResponseDataConnectedAccount.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DataIntegrationsListResponseDataConnectedAccount.from_dict(
            serialized
        )
        assert restored.to_dict() == serialized

    def test_data_integrations_list_response_data_connected_account_minimal_payload(
        self,
    ):
        data = {
            "object": "connected_account",
            "id": "data_installation_01EHZNVPK3SFK441A1RGBFSHRT",
            "user_id": None,
            "organization_id": None,
            "scopes": ["repo", "user:email"],
            "state": "connected",
            "created_at": "2024-01-16T14:20:00.000Z",
            "updated_at": "2024-01-16T14:20:00.000Z",
            "userlandUserId": None,
        }
        instance = DataIntegrationsListResponseDataConnectedAccount.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["scopes"] == data["scopes"]
        assert serialized["state"] == data["state"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]
        assert serialized["userlandUserId"] == data["userlandUserId"]

    def test_data_integrations_list_response_data_connected_account_omits_absent_optional_non_nullable_fields(
        self,
    ):
        data = {
            "object": "connected_account",
            "id": "data_installation_01EHZNVPK3SFK441A1RGBFSHRT",
            "user_id": "user_01EHZNVPK3SFK441A1RGBFSHRT",
            "organization_id": None,
            "scopes": ["repo", "user:email"],
            "api_key_last_4": None,
            "state": "connected",
            "created_at": "2024-01-16T14:20:00.000Z",
            "updated_at": "2024-01-16T14:20:00.000Z",
            "userlandUserId": "test_userlandUserId",
        }
        instance = DataIntegrationsListResponseDataConnectedAccount.from_dict(data)
        serialized = instance.to_dict()
        assert "auth_method" not in serialized

    def test_data_integrations_list_response_data_connected_account_preserves_nullable_fields(
        self,
    ):
        data = {
            "object": "connected_account",
            "id": "data_installation_01EHZNVPK3SFK441A1RGBFSHRT",
            "user_id": None,
            "organization_id": None,
            "scopes": ["repo", "user:email"],
            "auth_method": "oauth",
            "api_key_last_4": None,
            "state": "connected",
            "created_at": "2024-01-16T14:20:00.000Z",
            "updated_at": "2024-01-16T14:20:00.000Z",
            "userlandUserId": None,
        }
        instance = DataIntegrationsListResponseDataConnectedAccount.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["user_id"] is None
        assert serialized["organization_id"] is None
        assert serialized["api_key_last_4"] is None
        assert serialized["userlandUserId"] is None

    def test_data_integrations_list_response_data_connected_account_round_trips_unknown_enum_values(
        self,
    ):
        data = {
            "object": "connected_account",
            "id": "data_installation_01EHZNVPK3SFK441A1RGBFSHRT",
            "user_id": "user_01EHZNVPK3SFK441A1RGBFSHRT",
            "organization_id": None,
            "scopes": ["repo", "user:email"],
            "auth_method": "unexpected_data_integrations_list_response_data_connected_account_auth_method",
            "api_key_last_4": None,
            "state": "connected",
            "created_at": "2024-01-16T14:20:00.000Z",
            "updated_at": "2024-01-16T14:20:00.000Z",
            "userlandUserId": "test_userlandUserId",
        }
        instance = DataIntegrationsListResponseDataConnectedAccount.from_dict(data)
        assert instance.to_dict() == data
