# This file was auto-generated by Fern from our API Definition.

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.memory_detail_response import MemoryDetailResponse
from ..types.memory_list_response import MemoryListResponse
from ..types.memory_response import MemoryResponse
from ..types.memory_search_response import MemorySearchResponse
from ..types.reset_memories_response import ResetMemoriesResponse
from .raw_client import AsyncRawMemoriesClient, RawMemoriesClient
from .types.create_memory_request_category import CreateMemoryRequestCategory
from .types.create_memory_request_scope import CreateMemoryRequestScope
from .types.update_memory_request_category import UpdateMemoryRequestCategory
from .types.update_memory_request_scope import UpdateMemoryRequestScope

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class MemoriesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawMemoriesClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawMemoriesClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawMemoriesClient
        """
        return self._raw_client

    def list_memories(
        self,
        *,
        scope: typing.Optional[str] = None,
        category: typing.Optional[str] = None,
        organization_id: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MemoryListResponse:
        """
        Retrieve memories for the authenticated user with optional filters. Returns paginated results sorted by creation date descending.

        Parameters
        ----------
        scope : typing.Optional[str]
            Filter by scope: global or organization

        category : typing.Optional[str]
            Filter by category

        organization_id : typing.Optional[str]
            Filter by organization ID

        limit : typing.Optional[int]
            Page size (1-100)

        offset : typing.Optional[int]
            Offset for pagination

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        MemoryListResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.memories.list_memories()
        """
        _response = self._raw_client.list_memories(
            scope=scope,
            category=category,
            organization_id=organization_id,
            limit=limit,
            offset=offset,
            request_options=request_options,
        )
        return _response.data

    def create_memory(
        self,
        *,
        content: str,
        category: typing.Optional[CreateMemoryRequestCategory] = OMIT,
        scope: typing.Optional[CreateMemoryRequestScope] = OMIT,
        organization_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MemoryResponse:
        """
        Manually create a personal memory. Automatically checks for duplicates via embedding similarity. Returns the created or matched existing memory.

        Parameters
        ----------
        content : str
            The memory text

        category : typing.Optional[CreateMemoryRequestCategory]
            Category: fact, preference, instruction, context, biographical

        scope : typing.Optional[CreateMemoryRequestScope]
            Scope: global or organization

        organization_id : typing.Optional[str]
            Required when scope is organization

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        MemoryResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.memories.create_memory(
            content="content",
        )
        """
        _response = self._raw_client.create_memory(
            content=content,
            category=category,
            scope=scope,
            organization_id=organization_id,
            request_options=request_options,
        )
        return _response.data

    def reset_all_memories(
        self, *, confirm_reset: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> ResetMemoriesResponse:
        """
        Permanently delete all memories for the authenticated user. Requires the X-Confirm-Reset: true header as a safety measure.

        Parameters
        ----------
        confirm_reset : typing.Optional[str]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ResetMemoriesResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.memories.reset_all_memories()
        """
        _response = self._raw_client.reset_all_memories(confirm_reset=confirm_reset, request_options=request_options)
        return _response.data

    def get_memory(
        self, memory_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> MemoryDetailResponse:
        """
        Retrieve a single memory by ID, including source tracking fields.

        Parameters
        ----------
        memory_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        MemoryDetailResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.memories.get_memory(
            memory_id="memory_id",
        )
        """
        _response = self._raw_client.get_memory(memory_id, request_options=request_options)
        return _response.data

    def delete_memory(self, memory_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Permanently delete a single memory and its vector embedding.

        Parameters
        ----------
        memory_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.memories.delete_memory(
            memory_id="memory_id",
        )
        """
        _response = self._raw_client.delete_memory(memory_id, request_options=request_options)
        return _response.data

    def update_memory(
        self,
        memory_id: str,
        *,
        content: typing.Optional[str] = OMIT,
        category: typing.Optional[UpdateMemoryRequestCategory] = OMIT,
        scope: typing.Optional[UpdateMemoryRequestScope] = OMIT,
        organization_id: typing.Optional[str] = OMIT,
        is_pinned: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MemoryResponse:
        """
        Update a memory's content, category, scope, or pinned status. Re-embeds the content if it changed.

        Parameters
        ----------
        memory_id : str

        content : typing.Optional[str]

        category : typing.Optional[UpdateMemoryRequestCategory]

        scope : typing.Optional[UpdateMemoryRequestScope]

        organization_id : typing.Optional[str]

        is_pinned : typing.Optional[bool]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        MemoryResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.memories.update_memory(
            memory_id="memory_id",
        )
        """
        _response = self._raw_client.update_memory(
            memory_id,
            content=content,
            category=category,
            scope=scope,
            organization_id=organization_id,
            is_pinned=is_pinned,
            request_options=request_options,
        )
        return _response.data

    def search_memories(
        self, *, query: str, limit: typing.Optional[int] = OMIT, request_options: typing.Optional[RequestOptions] = None
    ) -> MemorySearchResponse:
        """
        Semantic search over the authenticated user's memories. Returns memories ranked by relevance to the query.

        Parameters
        ----------
        query : str
            Search query

        limit : typing.Optional[int]
            Max results (1-50)

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        MemorySearchResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.memories.search_memories(
            query="query",
        )
        """
        _response = self._raw_client.search_memories(query=query, limit=limit, request_options=request_options)
        return _response.data


class AsyncMemoriesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawMemoriesClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawMemoriesClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawMemoriesClient
        """
        return self._raw_client

    async def list_memories(
        self,
        *,
        scope: typing.Optional[str] = None,
        category: typing.Optional[str] = None,
        organization_id: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MemoryListResponse:
        """
        Retrieve memories for the authenticated user with optional filters. Returns paginated results sorted by creation date descending.

        Parameters
        ----------
        scope : typing.Optional[str]
            Filter by scope: global or organization

        category : typing.Optional[str]
            Filter by category

        organization_id : typing.Optional[str]
            Filter by organization ID

        limit : typing.Optional[int]
            Page size (1-100)

        offset : typing.Optional[int]
            Offset for pagination

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        MemoryListResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.memories.list_memories()


        asyncio.run(main())
        """
        _response = await self._raw_client.list_memories(
            scope=scope,
            category=category,
            organization_id=organization_id,
            limit=limit,
            offset=offset,
            request_options=request_options,
        )
        return _response.data

    async def create_memory(
        self,
        *,
        content: str,
        category: typing.Optional[CreateMemoryRequestCategory] = OMIT,
        scope: typing.Optional[CreateMemoryRequestScope] = OMIT,
        organization_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MemoryResponse:
        """
        Manually create a personal memory. Automatically checks for duplicates via embedding similarity. Returns the created or matched existing memory.

        Parameters
        ----------
        content : str
            The memory text

        category : typing.Optional[CreateMemoryRequestCategory]
            Category: fact, preference, instruction, context, biographical

        scope : typing.Optional[CreateMemoryRequestScope]
            Scope: global or organization

        organization_id : typing.Optional[str]
            Required when scope is organization

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        MemoryResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.memories.create_memory(
                content="content",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_memory(
            content=content,
            category=category,
            scope=scope,
            organization_id=organization_id,
            request_options=request_options,
        )
        return _response.data

    async def reset_all_memories(
        self, *, confirm_reset: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> ResetMemoriesResponse:
        """
        Permanently delete all memories for the authenticated user. Requires the X-Confirm-Reset: true header as a safety measure.

        Parameters
        ----------
        confirm_reset : typing.Optional[str]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ResetMemoriesResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.memories.reset_all_memories()


        asyncio.run(main())
        """
        _response = await self._raw_client.reset_all_memories(
            confirm_reset=confirm_reset, request_options=request_options
        )
        return _response.data

    async def get_memory(
        self, memory_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> MemoryDetailResponse:
        """
        Retrieve a single memory by ID, including source tracking fields.

        Parameters
        ----------
        memory_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        MemoryDetailResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.memories.get_memory(
                memory_id="memory_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_memory(memory_id, request_options=request_options)
        return _response.data

    async def delete_memory(self, memory_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Permanently delete a single memory and its vector embedding.

        Parameters
        ----------
        memory_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.memories.delete_memory(
                memory_id="memory_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete_memory(memory_id, request_options=request_options)
        return _response.data

    async def update_memory(
        self,
        memory_id: str,
        *,
        content: typing.Optional[str] = OMIT,
        category: typing.Optional[UpdateMemoryRequestCategory] = OMIT,
        scope: typing.Optional[UpdateMemoryRequestScope] = OMIT,
        organization_id: typing.Optional[str] = OMIT,
        is_pinned: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MemoryResponse:
        """
        Update a memory's content, category, scope, or pinned status. Re-embeds the content if it changed.

        Parameters
        ----------
        memory_id : str

        content : typing.Optional[str]

        category : typing.Optional[UpdateMemoryRequestCategory]

        scope : typing.Optional[UpdateMemoryRequestScope]

        organization_id : typing.Optional[str]

        is_pinned : typing.Optional[bool]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        MemoryResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.memories.update_memory(
                memory_id="memory_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_memory(
            memory_id,
            content=content,
            category=category,
            scope=scope,
            organization_id=organization_id,
            is_pinned=is_pinned,
            request_options=request_options,
        )
        return _response.data

    async def search_memories(
        self, *, query: str, limit: typing.Optional[int] = OMIT, request_options: typing.Optional[RequestOptions] = None
    ) -> MemorySearchResponse:
        """
        Semantic search over the authenticated user's memories. Returns memories ranked by relevance to the query.

        Parameters
        ----------
        query : str
            Search query

        limit : typing.Optional[int]
            Max results (1-50)

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        MemorySearchResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.memories.search_memories(
                query="query",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.search_memories(query=query, limit=limit, request_options=request_options)
        return _response.data
