# 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_task_tracker import AgentTaskTracker
from .raw_client import AsyncRawTrackerClient, RawTrackerClient

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


class TrackerClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawTrackerClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawTrackerClient
        """
        return self._raw_client

    def list(
        self,
        *,
        task_id: str,
        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[AgentTaskTracker]:
        """
        List agent task trackers for a task, optionally filtered by agent.

        Parameters
        ----------
        task_id : str
            Task ID (required for authorization)

        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[AgentTaskTracker]
            Successful Response

        Examples
        --------
        from terminaluse import TerminaluseApi

        client = TerminaluseApi(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.tracker.list(
            task_id="task_id",
        )
        """
        _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 retrieve(self, tracker_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> AgentTaskTracker:
        """
        Get agent task tracker by tracker ID

        Parameters
        ----------
        tracker_id : str

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

        Returns
        -------
        AgentTaskTracker
            Successful Response

        Examples
        --------
        from terminaluse import TerminaluseApi

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

    def update(
        self,
        tracker_id: str,
        *,
        last_processed_event_id: typing.Optional[str] = OMIT,
        status: typing.Optional[str] = OMIT,
        status_reason: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AgentTaskTracker:
        """
        Update agent task tracker by tracker ID

        Parameters
        ----------
        tracker_id : str

        last_processed_event_id : typing.Optional[str]
            The most recent processed event ID (omit to leave unchanged)

        status : typing.Optional[str]
            Processing status

        status_reason : typing.Optional[str]
            Optional status reason

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

        Returns
        -------
        AgentTaskTracker
            Successful Response

        Examples
        --------
        from terminaluse import TerminaluseApi

        client = TerminaluseApi(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.tracker.update(
            tracker_id="tracker_id",
        )
        """
        _response = self._raw_client.update(
            tracker_id,
            last_processed_event_id=last_processed_event_id,
            status=status,
            status_reason=status_reason,
            request_options=request_options,
        )
        return _response.data


class AsyncTrackerClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawTrackerClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawTrackerClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        task_id: str,
        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[AgentTaskTracker]:
        """
        List agent task trackers for a task, optionally filtered by agent.

        Parameters
        ----------
        task_id : str
            Task ID (required for authorization)

        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[AgentTaskTracker]
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminaluseApi

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


        async def main() -> None:
            await client.tracker.list(
                task_id="task_id",
            )


        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 retrieve(
        self, tracker_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AgentTaskTracker:
        """
        Get agent task tracker by tracker ID

        Parameters
        ----------
        tracker_id : str

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

        Returns
        -------
        AgentTaskTracker
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminaluseApi

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


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


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

    async def update(
        self,
        tracker_id: str,
        *,
        last_processed_event_id: typing.Optional[str] = OMIT,
        status: typing.Optional[str] = OMIT,
        status_reason: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AgentTaskTracker:
        """
        Update agent task tracker by tracker ID

        Parameters
        ----------
        tracker_id : str

        last_processed_event_id : typing.Optional[str]
            The most recent processed event ID (omit to leave unchanged)

        status : typing.Optional[str]
            Processing status

        status_reason : typing.Optional[str]
            Optional status reason

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

        Returns
        -------
        AgentTaskTracker
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminaluseApi

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


        async def main() -> None:
            await client.tracker.update(
                tracker_id="tracker_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            tracker_id,
            last_processed_event_id=last_processed_event_id,
            status=status,
            status_reason=status_reason,
            request_options=request_options,
        )
        return _response.data
