# 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_provider.models import (
    DataIntegrationConfigurationListResponse,
    DataIntegrationConfigurationResponse,
    DataIntegrationCredentials,
)


class TestModelRoundTrip:
    def test_data_integration_credentials_round_trip(self):
        data = load_fixture("data_integration_credentials.json")
        instance = DataIntegrationCredentials.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DataIntegrationCredentials.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_data_integration_credentials_minimal_payload(self):
        data = {
            "credentials_type": "organization",
            "has_credentials": True,
            "client_id": None,
            "client_secret_last_four": None,
            "redirect_uri": "https://api.workos.com/data-integrations/github/dik_01EHZNVPK3SFK441A1RGBFSHRT/callback",
        }
        instance = DataIntegrationCredentials.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["credentials_type"] == data["credentials_type"]
        assert serialized["has_credentials"] == data["has_credentials"]
        assert serialized["client_id"] == data["client_id"]
        assert serialized["client_secret_last_four"] == data["client_secret_last_four"]
        assert serialized["redirect_uri"] == data["redirect_uri"]

    def test_data_integration_credentials_preserves_nullable_fields(self):
        data = {
            "credentials_type": "organization",
            "has_credentials": True,
            "client_id": None,
            "client_secret_last_four": None,
            "redirect_uri": "https://api.workos.com/data-integrations/github/dik_01EHZNVPK3SFK441A1RGBFSHRT/callback",
        }
        instance = DataIntegrationCredentials.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["client_id"] is None
        assert serialized["client_secret_last_four"] is None

    def test_data_integration_credentials_round_trips_unknown_enum_values(self):
        data = {
            "credentials_type": "unexpected_data_integration_credentials_credentials_type",
            "has_credentials": True,
            "client_id": "client_01EHZNVPK3SFK441A1RGBFSHRT",
            "client_secret_last_four": "1a2b",
            "redirect_uri": "https://api.workos.com/data-integrations/github/dik_01EHZNVPK3SFK441A1RGBFSHRT/callback",
        }
        instance = DataIntegrationCredentials.from_dict(data)
        assert instance.to_dict() == data

    def test_data_integration_configuration_response_round_trip(self):
        data = load_fixture("data_integration_configuration_response.json")
        instance = DataIntegrationConfigurationResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DataIntegrationConfigurationResponse.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_data_integration_configuration_response_minimal_payload(self):
        data = {
            "object": "data_integration_configuration",
            "id": "data_integration_01EHZNVPK3SFK441A1RGBFSHRT",
            "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT",
            "slug": "github",
            "name": "GitHub",
            "enabled": True,
            "scopes": None,
            "config": {"account_identifier": "acme-prod"},
            "created_at": "2024-01-15T10:30:00.000Z",
            "updated_at": "2024-01-15T10:30:00.000Z",
        }
        instance = DataIntegrationConfigurationResponse.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["slug"] == data["slug"]
        assert serialized["name"] == data["name"]
        assert serialized["enabled"] == data["enabled"]
        assert serialized["scopes"] == data["scopes"]
        assert serialized["config"] == data["config"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]

    def test_data_integration_configuration_response_omits_absent_optional_non_nullable_fields(
        self,
    ):
        data = {
            "object": "data_integration_configuration",
            "id": "data_integration_01EHZNVPK3SFK441A1RGBFSHRT",
            "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT",
            "slug": "github",
            "name": "GitHub",
            "enabled": True,
            "scopes": ["repo", "user:email"],
            "config": {"account_identifier": "acme-prod"},
            "created_at": "2024-01-15T10:30:00.000Z",
            "updated_at": "2024-01-15T10:30:00.000Z",
        }
        instance = DataIntegrationConfigurationResponse.from_dict(data)
        serialized = instance.to_dict()
        assert "credentials" not in serialized

    def test_data_integration_configuration_response_preserves_nullable_fields(self):
        data = {
            "object": "data_integration_configuration",
            "id": "data_integration_01EHZNVPK3SFK441A1RGBFSHRT",
            "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT",
            "slug": "github",
            "name": "GitHub",
            "enabled": True,
            "scopes": None,
            "config": {"account_identifier": "acme-prod"},
            "created_at": "2024-01-15T10:30:00.000Z",
            "updated_at": "2024-01-15T10:30:00.000Z",
            "credentials": {
                "credentials_type": "organization",
                "has_credentials": True,
                "client_id": "client_01EHZNVPK3SFK441A1RGBFSHRT",
                "client_secret_last_four": "1a2b",
                "redirect_uri": "https://api.workos.com/data-integrations/github/dik_01EHZNVPK3SFK441A1RGBFSHRT/callback",
            },
        }
        instance = DataIntegrationConfigurationResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["scopes"] is None

    def test_data_integration_configuration_list_response_round_trip(self):
        data = load_fixture("data_integration_configuration_list_response.json")
        instance = DataIntegrationConfigurationListResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = DataIntegrationConfigurationListResponse.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_data_integration_configuration_list_response_minimal_payload(self):
        data = {
            "object": "list",
            "data": [
                {
                    "object": "data_integration_configuration",
                    "id": "data_integration_01EHZNVPK3SFK441A1RGBFSHRT",
                    "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT",
                    "slug": "github",
                    "name": "GitHub",
                    "enabled": True,
                    "scopes": ["repo", "user:email"],
                    "config": {"account_identifier": "acme-prod"},
                    "created_at": "2024-01-15T10:30:00.000Z",
                    "updated_at": "2024-01-15T10:30:00.000Z",
                    "credentials": {
                        "credentials_type": "organization",
                        "has_credentials": True,
                        "client_id": "client_01EHZNVPK3SFK441A1RGBFSHRT",
                        "client_secret_last_four": "1a2b",
                        "redirect_uri": "https://api.workos.com/data-integrations/github/dik_01EHZNVPK3SFK441A1RGBFSHRT/callback",
                    },
                }
            ],
        }
        instance = DataIntegrationConfigurationListResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["data"] == data["data"]
