# 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.agent_state import AgentState
from ...types.source import Source
from .raw_client import AsyncRawFoldersClient, RawFoldersClient
from .types.folders_list_request_order import FoldersListRequestOrder


class FoldersClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawFoldersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawFoldersClient
        """
        return self._raw_client

    def attach(
        self, agent_id: str, folder_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AgentState:
        """
        Attach a folder to an agent.

        Parameters
        ----------
        agent_id : str
            The ID of the source in the format 'source-<uuid4>'

        folder_id : str
            The ID of the agent in the format 'agent-<uuid4>'

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

        Returns
        -------
        AgentState
            Successful Response

        Examples
        --------
        from letta_client import Letta

        client = Letta(
            project="YOUR_PROJECT",
            token="YOUR_TOKEN",
        )
        client.agents.folders.attach(
            agent_id="source-123e4567-e89b-42d3-8456-426614174000",
            folder_id="agent-123e4567-e89b-42d3-8456-426614174000",
        )
        """
        _response = self._raw_client.attach(agent_id, folder_id, request_options=request_options)
        return _response.data

    def detach(
        self, agent_id: str, folder_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AgentState:
        """
        Detach a folder from an agent.

        Parameters
        ----------
        agent_id : str
            The ID of the source in the format 'source-<uuid4>'

        folder_id : str
            The ID of the agent in the format 'agent-<uuid4>'

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

        Returns
        -------
        AgentState
            Successful Response

        Examples
        --------
        from letta_client import Letta

        client = Letta(
            project="YOUR_PROJECT",
            token="YOUR_TOKEN",
        )
        client.agents.folders.detach(
            agent_id="source-123e4567-e89b-42d3-8456-426614174000",
            folder_id="agent-123e4567-e89b-42d3-8456-426614174000",
        )
        """
        _response = self._raw_client.detach(agent_id, folder_id, request_options=request_options)
        return _response.data

    def list(
        self,
        agent_id: str,
        *,
        before: typing.Optional[str] = None,
        after: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        order: typing.Optional[FoldersListRequestOrder] = None,
        order_by: typing.Optional[typing.Literal["created_at"]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[Source]:
        """
        Get the folders associated with an agent.

        Parameters
        ----------
        agent_id : str
            The ID of the agent in the format 'agent-<uuid4>'

        before : typing.Optional[str]
            Source ID cursor for pagination. Returns sources that come before this source ID in the specified sort order

        after : typing.Optional[str]
            Source ID cursor for pagination. Returns sources that come after this source ID in the specified sort order

        limit : typing.Optional[int]
            Maximum number of sources to return

        order : typing.Optional[FoldersListRequestOrder]
            Sort order for sources by creation time. 'asc' for oldest first, 'desc' for newest first

        order_by : typing.Optional[typing.Literal["created_at"]]
            Field to sort by

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

        Returns
        -------
        typing.List[Source]
            Successful Response

        Examples
        --------
        from letta_client import Letta

        client = Letta(
            project="YOUR_PROJECT",
            token="YOUR_TOKEN",
        )
        client.agents.folders.list(
            agent_id="agent-123e4567-e89b-42d3-8456-426614174000",
            before="before",
            after="after",
            limit=1,
            order="asc",
        )
        """
        _response = self._raw_client.list(
            agent_id,
            before=before,
            after=after,
            limit=limit,
            order=order,
            order_by=order_by,
            request_options=request_options,
        )
        return _response.data


class AsyncFoldersClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawFoldersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawFoldersClient
        """
        return self._raw_client

    async def attach(
        self, agent_id: str, folder_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AgentState:
        """
        Attach a folder to an agent.

        Parameters
        ----------
        agent_id : str
            The ID of the source in the format 'source-<uuid4>'

        folder_id : str
            The ID of the agent in the format 'agent-<uuid4>'

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

        Returns
        -------
        AgentState
            Successful Response

        Examples
        --------
        import asyncio

        from letta_client import AsyncLetta

        client = AsyncLetta(
            project="YOUR_PROJECT",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.agents.folders.attach(
                agent_id="source-123e4567-e89b-42d3-8456-426614174000",
                folder_id="agent-123e4567-e89b-42d3-8456-426614174000",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.attach(agent_id, folder_id, request_options=request_options)
        return _response.data

    async def detach(
        self, agent_id: str, folder_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AgentState:
        """
        Detach a folder from an agent.

        Parameters
        ----------
        agent_id : str
            The ID of the source in the format 'source-<uuid4>'

        folder_id : str
            The ID of the agent in the format 'agent-<uuid4>'

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

        Returns
        -------
        AgentState
            Successful Response

        Examples
        --------
        import asyncio

        from letta_client import AsyncLetta

        client = AsyncLetta(
            project="YOUR_PROJECT",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.agents.folders.detach(
                agent_id="source-123e4567-e89b-42d3-8456-426614174000",
                folder_id="agent-123e4567-e89b-42d3-8456-426614174000",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.detach(agent_id, folder_id, request_options=request_options)
        return _response.data

    async def list(
        self,
        agent_id: str,
        *,
        before: typing.Optional[str] = None,
        after: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        order: typing.Optional[FoldersListRequestOrder] = None,
        order_by: typing.Optional[typing.Literal["created_at"]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[Source]:
        """
        Get the folders associated with an agent.

        Parameters
        ----------
        agent_id : str
            The ID of the agent in the format 'agent-<uuid4>'

        before : typing.Optional[str]
            Source ID cursor for pagination. Returns sources that come before this source ID in the specified sort order

        after : typing.Optional[str]
            Source ID cursor for pagination. Returns sources that come after this source ID in the specified sort order

        limit : typing.Optional[int]
            Maximum number of sources to return

        order : typing.Optional[FoldersListRequestOrder]
            Sort order for sources by creation time. 'asc' for oldest first, 'desc' for newest first

        order_by : typing.Optional[typing.Literal["created_at"]]
            Field to sort by

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

        Returns
        -------
        typing.List[Source]
            Successful Response

        Examples
        --------
        import asyncio

        from letta_client import AsyncLetta

        client = AsyncLetta(
            project="YOUR_PROJECT",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.agents.folders.list(
                agent_id="agent-123e4567-e89b-42d3-8456-426614174000",
                before="before",
                after="after",
                limit=1,
                order="asc",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            agent_id,
            before=before,
            after=after,
            limit=limit,
            order=order,
            order_by=order_by,
            request_options=request_options,
        )
        return _response.data
