"""
tests/core/organs/test_unified_memory.py — Unified Memory Tests

Tests for unified_memory.py — testing actual available functions
"""

import pytest


class TestUnifiedMemory:
    """Test unified memory operations."""

    def test_get_unified_memory(self):
        """Test getting unified memory instance."""
        from core.organs.unified_memory import get_unified_memory

        memory = get_unified_memory()
        assert memory is not None

    @pytest.mark.asyncio
    async def test_vault_operation(self):
        """Test vault operation through unified_memory."""
        from core.organs.unified_memory import vault

        result = await vault(
            operation="seal", session_id="test-vault-001", summary="Test seal operation"
        )

        assert result is not None

    @pytest.mark.asyncio
    async def test_vault_store_and_retrieve(self):
        """Test storing and retrieving through vault."""
        from core.organs.unified_memory import vault

        # Store
        store_result = await vault(
            operation="store",
            session_id="test-vault-002",
            key="test_key",
            value={"data": "test value"},
        )

        assert store_result is not None

        # Retrieve
        retrieve_result = await vault(
            operation="retrieve", session_id="test-vault-002", key="test_key"
        )

        assert retrieve_result is not None

    def test_unified_memory_class(self):
        """Test UnifiedMemory class instantiation."""
        from core.organs.unified_memory import UnifiedMemory

        memory = UnifiedMemory()
        assert memory is not None

    @pytest.mark.asyncio
    async def test_vault_list(self):
        """Test listing vault entries."""
        from core.organs.unified_memory import vault

        result = await vault(operation="list", session_id="test-vault-003")

        assert result is not None

    @pytest.mark.asyncio
    async def test_vault_with_metadata(self):
        """Test vault with metadata."""
        from core.organs.unified_memory import vault

        result = await vault(
            operation="seal",
            session_id="test-vault-004",
            summary="Test with metadata",
            metadata={"author": "test", "tags": ["test", "seal"]},
        )

        assert result is not None


class TestUnifiedMemoryEdgeCases:
    """Edge cases for unified memory."""

    @pytest.mark.asyncio
    async def test_vault_empty_session(self):
        """Test vault with empty session."""
        from core.organs.unified_memory import vault

        result = await vault(operation="seal", session_id="", summary="Empty session test")

        assert result is not None

    @pytest.mark.asyncio
    async def test_vault_unicode_content(self):
        """Test vault with unicode."""
        from core.organs.unified_memory import vault

        result = await vault(
            operation="seal", session_id="test-unicode", summary="Unicode: 你好 🌍 ñ"
        )

        assert result is not None
