# 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.audit_logs.models import (
    AuditLogAction,
    AuditLogEvent,
    AuditLogEventActor,
    AuditLogEventContext,
    AuditLogEventCreateResponse,
    AuditLogEventTarget,
    AuditLogExport,
    AuditLogSchema,
    AuditLogSchemaActor,
    AuditLogSchemaActorInput,
    AuditLogSchemaTarget,
    AuditLogSchemaTargetInput,
)


class TestModelRoundTrip:
    def test_audit_log_event_actor_round_trip(self):
        data = load_fixture("audit_log_event_actor.json")
        instance = AuditLogEventActor.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = AuditLogEventActor.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_audit_log_event_actor_minimal_payload(self):
        data = {"id": "user_TF4C5938", "type": "user"}
        instance = AuditLogEventActor.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["id"] == data["id"]
        assert serialized["type"] == data["type"]

    def test_audit_log_event_actor_omits_absent_optional_non_nullable_fields(self):
        data = {"id": "user_TF4C5938", "type": "user"}
        instance = AuditLogEventActor.from_dict(data)
        serialized = instance.to_dict()
        assert "name" not in serialized
        assert "metadata" not in serialized

    def test_audit_log_event_target_round_trip(self):
        data = load_fixture("audit_log_event_target.json")
        instance = AuditLogEventTarget.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = AuditLogEventTarget.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_audit_log_event_target_minimal_payload(self):
        data = {"id": "user_TF4C5938", "type": "user"}
        instance = AuditLogEventTarget.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["id"] == data["id"]
        assert serialized["type"] == data["type"]

    def test_audit_log_event_target_omits_absent_optional_non_nullable_fields(self):
        data = {"id": "user_TF4C5938", "type": "user"}
        instance = AuditLogEventTarget.from_dict(data)
        serialized = instance.to_dict()
        assert "name" not in serialized
        assert "metadata" not in serialized

    def test_audit_log_event_context_round_trip(self):
        data = load_fixture("audit_log_event_context.json")
        instance = AuditLogEventContext.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = AuditLogEventContext.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_audit_log_event_context_minimal_payload(self):
        data = {"location": "123.123.123.123"}
        instance = AuditLogEventContext.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["location"] == data["location"]

    def test_audit_log_event_context_omits_absent_optional_non_nullable_fields(self):
        data = {"location": "123.123.123.123"}
        instance = AuditLogEventContext.from_dict(data)
        serialized = instance.to_dict()
        assert "user_agent" not in serialized

    def test_audit_log_event_round_trip(self):
        data = load_fixture("audit_log_event.json")
        instance = AuditLogEvent.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = AuditLogEvent.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_audit_log_event_minimal_payload(self):
        data = {
            "action": "user.signed_in",
            "occurred_at": "2026-02-02T16:35:39.000Z",
            "actor": {
                "id": "user_TF4C5938",
                "type": "user",
                "name": "Jon Smith",
                "metadata": {"owner": "user_01GBTCQ2"},
            },
            "targets": [
                {
                    "id": "user_TF4C5938",
                    "type": "user",
                    "name": "Jon Smith",
                    "metadata": {"owner": "user_01GBTCQ2"},
                }
            ],
            "context": {
                "location": "123.123.123.123",
                "user_agent": "Chrome/104.0.0.0",
            },
        }
        instance = AuditLogEvent.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["action"] == data["action"]
        assert serialized["occurred_at"] == data["occurred_at"]
        assert serialized["actor"] == data["actor"]
        assert serialized["targets"] == data["targets"]
        assert serialized["context"] == data["context"]

    def test_audit_log_event_omits_absent_optional_non_nullable_fields(self):
        data = {
            "action": "user.signed_in",
            "occurred_at": "2026-02-02T16:35:39.000Z",
            "actor": {
                "id": "user_TF4C5938",
                "type": "user",
                "name": "Jon Smith",
                "metadata": {"owner": "user_01GBTCQ2"},
            },
            "targets": [
                {
                    "id": "user_TF4C5938",
                    "type": "user",
                    "name": "Jon Smith",
                    "metadata": {"owner": "user_01GBTCQ2"},
                }
            ],
            "context": {
                "location": "123.123.123.123",
                "user_agent": "Chrome/104.0.0.0",
            },
        }
        instance = AuditLogEvent.from_dict(data)
        serialized = instance.to_dict()
        assert "metadata" not in serialized
        assert "version" not in serialized

    def test_audit_log_schema_actor_input_round_trip(self):
        data = load_fixture("audit_log_schema_actor_input.json")
        instance = AuditLogSchemaActorInput.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = AuditLogSchemaActorInput.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_audit_log_schema_actor_input_minimal_payload(self):
        data = {
            "metadata": {"type": "object", "properties": {"role": {"type": "string"}}}
        }
        instance = AuditLogSchemaActorInput.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["metadata"] == data["metadata"]

    def test_audit_log_schema_target_input_round_trip(self):
        data = load_fixture("audit_log_schema_target_input.json")
        instance = AuditLogSchemaTargetInput.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = AuditLogSchemaTargetInput.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_audit_log_schema_target_input_minimal_payload(self):
        data = {"type": "invoice"}
        instance = AuditLogSchemaTargetInput.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["type"] == data["type"]

    def test_audit_log_schema_target_input_omits_absent_optional_non_nullable_fields(
        self,
    ):
        data = {"type": "invoice"}
        instance = AuditLogSchemaTargetInput.from_dict(data)
        serialized = instance.to_dict()
        assert "metadata" not in serialized

    def test_audit_log_event_create_response_round_trip(self):
        data = load_fixture("audit_log_event_create_response.json")
        instance = AuditLogEventCreateResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = AuditLogEventCreateResponse.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_audit_log_event_create_response_minimal_payload(self):
        data = {"success": True}
        instance = AuditLogEventCreateResponse.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["success"] == data["success"]

    def test_audit_log_export_round_trip(self):
        data = load_fixture("audit_log_export.json")
        instance = AuditLogExport.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = AuditLogExport.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_audit_log_export_minimal_payload(self):
        data = {
            "object": "audit_log_export",
            "id": "audit_log_export_01GBZK5MP7TD1YCFQHFR22180V",
            "state": "ready",
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = AuditLogExport.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["id"] == data["id"]
        assert serialized["state"] == data["state"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]

    def test_audit_log_export_preserves_nullable_fields(self):
        data = {
            "object": "audit_log_export",
            "id": "audit_log_export_01GBZK5MP7TD1YCFQHFR22180V",
            "state": "ready",
            "url": None,
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = AuditLogExport.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["url"] is None

    def test_audit_log_export_round_trips_unknown_enum_values(self):
        data = {
            "object": "audit_log_export",
            "id": "audit_log_export_01GBZK5MP7TD1YCFQHFR22180V",
            "state": "unexpected_audit_log_export_state",
            "url": "https://exports.audit-logs.com/audit-log-exports/export.csv",
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = AuditLogExport.from_dict(data)
        assert instance.to_dict() == data

    def test_audit_log_schema_round_trip(self):
        data = load_fixture("audit_log_schema.json")
        instance = AuditLogSchema.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = AuditLogSchema.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_audit_log_schema_minimal_payload(self):
        data = {
            "object": "audit_log_schema",
            "version": 1,
            "targets": [
                {
                    "type": "invoice",
                    "metadata": {
                        "type": "object",
                        "properties": {"cost": {"type": "number"}},
                    },
                }
            ],
            "created_at": "2026-01-15T12:00:00.000Z",
        }
        instance = AuditLogSchema.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["version"] == data["version"]
        assert serialized["targets"] == data["targets"]
        assert serialized["created_at"] == data["created_at"]

    def test_audit_log_schema_omits_absent_optional_non_nullable_fields(self):
        data = {
            "object": "audit_log_schema",
            "version": 1,
            "targets": [
                {
                    "type": "invoice",
                    "metadata": {
                        "type": "object",
                        "properties": {"cost": {"type": "number"}},
                    },
                }
            ],
            "created_at": "2026-01-15T12:00:00.000Z",
        }
        instance = AuditLogSchema.from_dict(data)
        serialized = instance.to_dict()
        assert "actor" not in serialized
        assert "metadata" not in serialized

    def test_audit_log_action_round_trip(self):
        data = load_fixture("audit_log_action.json")
        instance = AuditLogAction.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = AuditLogAction.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_audit_log_action_minimal_payload(self):
        data = {
            "object": "audit_log_action",
            "name": "user.viewed_invoice",
            "schema": {
                "object": "audit_log_schema",
                "version": 1,
                "actor": {
                    "metadata": {
                        "type": "object",
                        "properties": {"role": {"type": "string"}},
                    }
                },
                "targets": [
                    {
                        "type": "invoice",
                        "metadata": {
                            "type": "object",
                            "properties": {"cost": {"type": "number"}},
                        },
                    }
                ],
                "metadata": {
                    "type": "object",
                    "properties": {"transactionId": {"type": "string"}},
                },
                "created_at": "2026-01-15T12:00:00.000Z",
            },
            "created_at": "2026-01-15T12:00:00.000Z",
            "updated_at": "2026-01-15T12:00:00.000Z",
        }
        instance = AuditLogAction.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["object"] == data["object"]
        assert serialized["name"] == data["name"]
        assert serialized["schema"] == data["schema"]
        assert serialized["created_at"] == data["created_at"]
        assert serialized["updated_at"] == data["updated_at"]

    def test_audit_log_schema_actor_round_trip(self):
        data = load_fixture("audit_log_schema_actor.json")
        instance = AuditLogSchemaActor.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = AuditLogSchemaActor.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_audit_log_schema_actor_minimal_payload(self):
        data = {"metadata": {"key": {}}}
        instance = AuditLogSchemaActor.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["metadata"] == data["metadata"]

    def test_audit_log_schema_target_round_trip(self):
        data = load_fixture("audit_log_schema_target.json")
        instance = AuditLogSchemaTarget.from_dict(data)
        serialized = instance.to_dict()
        assert serialized == data
        restored = AuditLogSchemaTarget.from_dict(serialized)
        assert restored.to_dict() == serialized

    def test_audit_log_schema_target_minimal_payload(self):
        data = {"type": "invoice"}
        instance = AuditLogSchemaTarget.from_dict(data)
        serialized = instance.to_dict()
        assert serialized["type"] == data["type"]

    def test_audit_log_schema_target_omits_absent_optional_non_nullable_fields(self):
        data = {"type": "invoice"}
        instance = AuditLogSchemaTarget.from_dict(data)
        serialized = instance.to_dict()
        assert "metadata" not in serialized
