# 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.personal_knowledge_settings_response import PersonalKnowledgeSettingsResponse
from ..types.personal_store_file_list_response import PersonalStoreFileListResponse
from ..types.personal_store_file_response import PersonalStoreFileResponse
from ..types.personal_store_list_response import PersonalStoreListResponse
from ..types.personal_store_response import PersonalStoreResponse
from ..types.teach_response import TeachResponse
from .raw_client import AsyncRawPersonalKnowledgeClient, RawPersonalKnowledgeClient

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


class PersonalKnowledgeClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawPersonalKnowledgeClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawPersonalKnowledgeClient
        """
        return self._raw_client

    def list_personal_stores(
        self,
        *,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PersonalStoreListResponse:
        """
        Retrieve all personal vector stores for the authenticated user. Returns stores ordered by creation date, with the default store included.

        Parameters
        ----------
        limit : typing.Optional[int]
            Number of stores to return

        offset : typing.Optional[int]
            Number of stores to skip

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

        Returns
        -------
        PersonalStoreListResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.personal_knowledge.list_personal_stores()
        """
        _response = self._raw_client.list_personal_stores(limit=limit, offset=offset, request_options=request_options)
        return _response.data

    def create_personal_store(
        self,
        *,
        name: str,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PersonalStoreResponse:
        """
        Create an additional personal vector store. Each user can have multiple stores to organize different topics.

        Parameters
        ----------
        name : str
            Store name

        description : typing.Optional[str]
            Optional description

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

        Returns
        -------
        PersonalStoreResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.personal_knowledge.create_personal_store(
            name="name",
        )
        """
        _response = self._raw_client.create_personal_store(
            name=name, description=description, request_options=request_options
        )
        return _response.data

    def get_personal_store(
        self, store_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> PersonalStoreResponse:
        """
        Retrieve details of a specific personal vector store. Only accessible by the store owner.

        Parameters
        ----------
        store_id : str

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

        Returns
        -------
        PersonalStoreResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.personal_knowledge.get_personal_store(
            store_id="store_id",
        )
        """
        _response = self._raw_client.get_personal_store(store_id, request_options=request_options)
        return _response.data

    def delete_personal_store(self, store_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Delete a personal vector store. The default store cannot be deleted (returns 409).

        Parameters
        ----------
        store_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.personal_knowledge.delete_personal_store(
            store_id="store_id",
        )
        """
        _response = self._raw_client.delete_personal_store(store_id, request_options=request_options)
        return _response.data

    def update_personal_store(
        self,
        store_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PersonalStoreResponse:
        """
        Update the name or description of a personal vector store.

        Parameters
        ----------
        store_id : str

        name : typing.Optional[str]

        description : typing.Optional[str]

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

        Returns
        -------
        PersonalStoreResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.personal_knowledge.update_personal_store(
            store_id="store_id",
        )
        """
        _response = self._raw_client.update_personal_store(
            store_id, name=name, description=description, request_options=request_options
        )
        return _response.data

    def list_store_files(
        self,
        store_id: str,
        *,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PersonalStoreFileListResponse:
        """
        Retrieve all files associated with a personal vector store. Returns files ordered by when they were added.

        Parameters
        ----------
        store_id : str

        limit : typing.Optional[int]
            Number of files to return

        offset : typing.Optional[int]
            Number of files to skip

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

        Returns
        -------
        PersonalStoreFileListResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.personal_knowledge.list_store_files(
            store_id="store_id",
        )
        """
        _response = self._raw_client.list_store_files(
            store_id, limit=limit, offset=offset, request_options=request_options
        )
        return _response.data

    def add_file_to_store(
        self, store_id: str, *, file_id: str, request_options: typing.Optional[RequestOptions] = None
    ) -> PersonalStoreFileResponse:
        """
        Associate an existing file with a personal vector store. The file must already be uploaded via the POST /v1/files endpoint.

        Parameters
        ----------
        store_id : str

        file_id : str
            ID of a previously uploaded file

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

        Returns
        -------
        PersonalStoreFileResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.personal_knowledge.add_file_to_store(
            store_id="store_id",
            file_id="file_id",
        )
        """
        _response = self._raw_client.add_file_to_store(store_id, file_id=file_id, request_options=request_options)
        return _response.data

    def remove_file_from_store(
        self, store_id: str, file_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Remove a file association from a personal vector store. This does not delete the underlying file.

        Parameters
        ----------
        store_id : str

        file_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.personal_knowledge.remove_file_from_store(
            store_id="store_id",
            file_id="file_id",
        )
        """
        _response = self._raw_client.remove_file_from_store(store_id, file_id, request_options=request_options)
        return _response.data

    def teach(
        self,
        *,
        content: str,
        store_id: typing.Optional[str] = OMIT,
        category: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TeachResponse:
        """
        Submit free-text content to be chunked, embedded, and stored in the user's personal vector store. If no store_id is specified, uses the default personal store. Content is limited to 10,000 characters.

        Parameters
        ----------
        content : str
            Text content to add as personal knowledge

        store_id : typing.Optional[str]
            Target store ID. Uses default if not specified.

        category : typing.Optional[str]
            Optional category tag for the content

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

        Returns
        -------
        TeachResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.personal_knowledge.teach(
            content="content",
        )
        """
        _response = self._raw_client.teach(
            content=content, store_id=store_id, category=category, request_options=request_options
        )
        return _response.data

    def get_settings(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> PersonalKnowledgeSettingsResponse:
        """
        Retrieve the authenticated user's personal knowledge settings. Auto-provisions defaults on first access — always returns 200, never 404.

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

        Returns
        -------
        PersonalKnowledgeSettingsResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.personal_knowledge.get_settings()
        """
        _response = self._raw_client.get_settings(request_options=request_options)
        return _response.data

    def update_settings(
        self,
        *,
        revision: int,
        memories_enabled: typing.Optional[bool] = OMIT,
        auto_extract_enabled: typing.Optional[bool] = OMIT,
        personal_knowledge_enabled: typing.Optional[bool] = OMIT,
        config: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PersonalKnowledgeSettingsResponse:
        """
        Update the authenticated user's personal knowledge settings with optimistic concurrency. The revision field must match the current server revision or a 409 Conflict will be returned.

        Parameters
        ----------
        revision : int
            Required for optimistic concurrency — must match current server revision

        memories_enabled : typing.Optional[bool]
            Enable/disable memories feature

        auto_extract_enabled : typing.Optional[bool]
            Enable/disable automatic memory extraction from conversations

        personal_knowledge_enabled : typing.Optional[bool]
            Enable/disable personal knowledge stores

        config : typing.Optional[typing.Dict[str, typing.Any]]
            Additional configuration overrides

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

        Returns
        -------
        PersonalKnowledgeSettingsResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.personal_knowledge.update_settings(
            revision=1,
        )
        """
        _response = self._raw_client.update_settings(
            revision=revision,
            memories_enabled=memories_enabled,
            auto_extract_enabled=auto_extract_enabled,
            personal_knowledge_enabled=personal_knowledge_enabled,
            config=config,
            request_options=request_options,
        )
        return _response.data


class AsyncPersonalKnowledgeClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawPersonalKnowledgeClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawPersonalKnowledgeClient
        """
        return self._raw_client

    async def list_personal_stores(
        self,
        *,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PersonalStoreListResponse:
        """
        Retrieve all personal vector stores for the authenticated user. Returns stores ordered by creation date, with the default store included.

        Parameters
        ----------
        limit : typing.Optional[int]
            Number of stores to return

        offset : typing.Optional[int]
            Number of stores to skip

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

        Returns
        -------
        PersonalStoreListResponse
            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.personal_knowledge.list_personal_stores()


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

    async def create_personal_store(
        self,
        *,
        name: str,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PersonalStoreResponse:
        """
        Create an additional personal vector store. Each user can have multiple stores to organize different topics.

        Parameters
        ----------
        name : str
            Store name

        description : typing.Optional[str]
            Optional description

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

        Returns
        -------
        PersonalStoreResponse
            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.personal_knowledge.create_personal_store(
                name="name",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_personal_store(
            name=name, description=description, request_options=request_options
        )
        return _response.data

    async def get_personal_store(
        self, store_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> PersonalStoreResponse:
        """
        Retrieve details of a specific personal vector store. Only accessible by the store owner.

        Parameters
        ----------
        store_id : str

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

        Returns
        -------
        PersonalStoreResponse
            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.personal_knowledge.get_personal_store(
                store_id="store_id",
            )


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

    async def delete_personal_store(
        self, store_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete a personal vector store. The default store cannot be deleted (returns 409).

        Parameters
        ----------
        store_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.personal_knowledge.delete_personal_store(
                store_id="store_id",
            )


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

    async def update_personal_store(
        self,
        store_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PersonalStoreResponse:
        """
        Update the name or description of a personal vector store.

        Parameters
        ----------
        store_id : str

        name : typing.Optional[str]

        description : typing.Optional[str]

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

        Returns
        -------
        PersonalStoreResponse
            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.personal_knowledge.update_personal_store(
                store_id="store_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_personal_store(
            store_id, name=name, description=description, request_options=request_options
        )
        return _response.data

    async def list_store_files(
        self,
        store_id: str,
        *,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PersonalStoreFileListResponse:
        """
        Retrieve all files associated with a personal vector store. Returns files ordered by when they were added.

        Parameters
        ----------
        store_id : str

        limit : typing.Optional[int]
            Number of files to return

        offset : typing.Optional[int]
            Number of files to skip

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

        Returns
        -------
        PersonalStoreFileListResponse
            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.personal_knowledge.list_store_files(
                store_id="store_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list_store_files(
            store_id, limit=limit, offset=offset, request_options=request_options
        )
        return _response.data

    async def add_file_to_store(
        self, store_id: str, *, file_id: str, request_options: typing.Optional[RequestOptions] = None
    ) -> PersonalStoreFileResponse:
        """
        Associate an existing file with a personal vector store. The file must already be uploaded via the POST /v1/files endpoint.

        Parameters
        ----------
        store_id : str

        file_id : str
            ID of a previously uploaded file

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

        Returns
        -------
        PersonalStoreFileResponse
            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.personal_knowledge.add_file_to_store(
                store_id="store_id",
                file_id="file_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.add_file_to_store(store_id, file_id=file_id, request_options=request_options)
        return _response.data

    async def remove_file_from_store(
        self, store_id: str, file_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Remove a file association from a personal vector store. This does not delete the underlying file.

        Parameters
        ----------
        store_id : str

        file_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.personal_knowledge.remove_file_from_store(
                store_id="store_id",
                file_id="file_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.remove_file_from_store(store_id, file_id, request_options=request_options)
        return _response.data

    async def teach(
        self,
        *,
        content: str,
        store_id: typing.Optional[str] = OMIT,
        category: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TeachResponse:
        """
        Submit free-text content to be chunked, embedded, and stored in the user's personal vector store. If no store_id is specified, uses the default personal store. Content is limited to 10,000 characters.

        Parameters
        ----------
        content : str
            Text content to add as personal knowledge

        store_id : typing.Optional[str]
            Target store ID. Uses default if not specified.

        category : typing.Optional[str]
            Optional category tag for the content

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

        Returns
        -------
        TeachResponse
            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.personal_knowledge.teach(
                content="content",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.teach(
            content=content, store_id=store_id, category=category, request_options=request_options
        )
        return _response.data

    async def get_settings(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> PersonalKnowledgeSettingsResponse:
        """
        Retrieve the authenticated user's personal knowledge settings. Auto-provisions defaults on first access — always returns 200, never 404.

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

        Returns
        -------
        PersonalKnowledgeSettingsResponse
            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.personal_knowledge.get_settings()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_settings(request_options=request_options)
        return _response.data

    async def update_settings(
        self,
        *,
        revision: int,
        memories_enabled: typing.Optional[bool] = OMIT,
        auto_extract_enabled: typing.Optional[bool] = OMIT,
        personal_knowledge_enabled: typing.Optional[bool] = OMIT,
        config: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PersonalKnowledgeSettingsResponse:
        """
        Update the authenticated user's personal knowledge settings with optimistic concurrency. The revision field must match the current server revision or a 409 Conflict will be returned.

        Parameters
        ----------
        revision : int
            Required for optimistic concurrency — must match current server revision

        memories_enabled : typing.Optional[bool]
            Enable/disable memories feature

        auto_extract_enabled : typing.Optional[bool]
            Enable/disable automatic memory extraction from conversations

        personal_knowledge_enabled : typing.Optional[bool]
            Enable/disable personal knowledge stores

        config : typing.Optional[typing.Dict[str, typing.Any]]
            Additional configuration overrides

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

        Returns
        -------
        PersonalKnowledgeSettingsResponse
            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.personal_knowledge.update_settings(
                revision=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_settings(
            revision=revision,
            memories_enabled=memories_enabled,
            auto_extract_enabled=auto_extract_enabled,
            personal_knowledge_enabled=personal_knowledge_enabled,
            config=config,
            request_options=request_options,
        )
        return _response.data
