# 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.state import State
from .raw_client import AsyncRawStatesClient, RawStatesClient

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


class StatesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawStatesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawStatesClient
        """
        return self._raw_client

    def list(
        self,
        *,
        task_id: typing.Optional[str] = None,
        agent_id: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        page_number: typing.Optional[int] = None,
        order_by: typing.Optional[str] = None,
        order_direction: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[State]:
        """
        List all states, filtered by task_id or agent_id (at least one required).

        Parameters
        ----------
        task_id : typing.Optional[str]
            Task ID

        agent_id : typing.Optional[str]
            Agent ID

        limit : typing.Optional[int]
            Limit

        page_number : typing.Optional[int]
            Page number

        order_by : typing.Optional[str]
            Field to order by

        order_direction : typing.Optional[str]
            Order direction (asc or desc)

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

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

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.states.list()
        """
        _response = self._raw_client.list(
            task_id=task_id,
            agent_id=agent_id,
            limit=limit,
            page_number=page_number,
            order_by=order_by,
            order_direction=order_direction,
            request_options=request_options,
        )
        return _response.data

    def create(
        self,
        *,
        agent_id: str,
        state: typing.Dict[str, typing.Any],
        task_id: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> State:
        """
        Parameters
        ----------
        agent_id : str

        state : typing.Dict[str, typing.Any]

        task_id : str

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

        Returns
        -------
        State
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.states.create(
            agent_id="agent_id",
            state={"key": "value"},
            task_id="task_id",
        )
        """
        _response = self._raw_client.create(
            agent_id=agent_id, state=state, task_id=task_id, request_options=request_options
        )
        return _response.data

    def retrieve(self, state_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> State:
        """
        Get a state by its unique state ID.

        Parameters
        ----------
        state_id : str

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

        Returns
        -------
        State
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.states.retrieve(
            state_id="state_id",
        )
        """
        _response = self._raw_client.retrieve(state_id, request_options=request_options)
        return _response.data

    def update(
        self,
        state_id: str,
        *,
        agent_id: str,
        state: typing.Dict[str, typing.Any],
        task_id: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> State:
        """
        Parameters
        ----------
        state_id : str

        agent_id : str

        state : typing.Dict[str, typing.Any]

        task_id : str

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

        Returns
        -------
        State
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.states.update(
            state_id="state_id",
            agent_id="agent_id",
            state={"key": "value"},
            task_id="task_id",
        )
        """
        _response = self._raw_client.update(
            state_id, agent_id=agent_id, state=state, task_id=task_id, request_options=request_options
        )
        return _response.data

    def delete(self, state_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> State:
        """
        Parameters
        ----------
        state_id : str

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

        Returns
        -------
        State
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.states.delete(
            state_id="state_id",
        )
        """
        _response = self._raw_client.delete(state_id, request_options=request_options)
        return _response.data


class AsyncStatesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawStatesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawStatesClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        task_id: typing.Optional[str] = None,
        agent_id: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        page_number: typing.Optional[int] = None,
        order_by: typing.Optional[str] = None,
        order_direction: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[State]:
        """
        List all states, filtered by task_id or agent_id (at least one required).

        Parameters
        ----------
        task_id : typing.Optional[str]
            Task ID

        agent_id : typing.Optional[str]
            Agent ID

        limit : typing.Optional[int]
            Limit

        page_number : typing.Optional[int]
            Page number

        order_by : typing.Optional[str]
            Field to order by

        order_direction : typing.Optional[str]
            Order direction (asc or desc)

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

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

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.states.list()


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            task_id=task_id,
            agent_id=agent_id,
            limit=limit,
            page_number=page_number,
            order_by=order_by,
            order_direction=order_direction,
            request_options=request_options,
        )
        return _response.data

    async def create(
        self,
        *,
        agent_id: str,
        state: typing.Dict[str, typing.Any],
        task_id: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> State:
        """
        Parameters
        ----------
        agent_id : str

        state : typing.Dict[str, typing.Any]

        task_id : str

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

        Returns
        -------
        State
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.states.create(
                agent_id="agent_id",
                state={"key": "value"},
                task_id="task_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            agent_id=agent_id, state=state, task_id=task_id, request_options=request_options
        )
        return _response.data

    async def retrieve(self, state_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> State:
        """
        Get a state by its unique state ID.

        Parameters
        ----------
        state_id : str

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

        Returns
        -------
        State
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.states.retrieve(
                state_id="state_id",
            )


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

    async def update(
        self,
        state_id: str,
        *,
        agent_id: str,
        state: typing.Dict[str, typing.Any],
        task_id: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> State:
        """
        Parameters
        ----------
        state_id : str

        agent_id : str

        state : typing.Dict[str, typing.Any]

        task_id : str

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

        Returns
        -------
        State
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.states.update(
                state_id="state_id",
                agent_id="agent_id",
                state={"key": "value"},
                task_id="task_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            state_id, agent_id=agent_id, state=state, task_id=task_id, request_options=request_options
        )
        return _response.data

    async def delete(self, state_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> State:
        """
        Parameters
        ----------
        state_id : str

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

        Returns
        -------
        State
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.states.delete(
                state_id="state_id",
            )


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