# 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.version_list_response import VersionListResponse
from ...types.version_status import VersionStatus
from .raw_client import AsyncRawVersionsClient, RawVersionsClient


class VersionsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawVersionsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawVersionsClient
        """
        return self._raw_client

    def list(
        self,
        namespace_slug: str,
        agent_name: str,
        *,
        branch: typing.Optional[str] = None,
        status: typing.Optional[VersionStatus] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> VersionListResponse:
        """
        List all versions for an agent.

            Optionally filter by branch name or version status.
            Versions are ordered by deployed_at descending (most recent first).

        Parameters
        ----------
        namespace_slug : str

        agent_name : str

        branch : typing.Optional[str]
            Filter by branch name (e.g., 'main', 'feature/login'). If not provided, returns versions across all branches.

        status : typing.Optional[VersionStatus]
            Filter by version status

        limit : typing.Optional[int]
            Maximum versions to return

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

        Returns
        -------
        VersionListResponse
            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.agents.versions.list(
            namespace_slug="namespace_slug",
            agent_name="agent_name",
        )
        """
        _response = self._raw_client.list(
            namespace_slug, agent_name, branch=branch, status=status, limit=limit, request_options=request_options
        )
        return _response.data


class AsyncVersionsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawVersionsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawVersionsClient
        """
        return self._raw_client

    async def list(
        self,
        namespace_slug: str,
        agent_name: str,
        *,
        branch: typing.Optional[str] = None,
        status: typing.Optional[VersionStatus] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> VersionListResponse:
        """
        List all versions for an agent.

            Optionally filter by branch name or version status.
            Versions are ordered by deployed_at descending (most recent first).

        Parameters
        ----------
        namespace_slug : str

        agent_name : str

        branch : typing.Optional[str]
            Filter by branch name (e.g., 'main', 'feature/login'). If not provided, returns versions across all branches.

        status : typing.Optional[VersionStatus]
            Filter by version status

        limit : typing.Optional[int]
            Maximum versions to return

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

        Returns
        -------
        VersionListResponse
            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.agents.versions.list(
                namespace_slug="namespace_slug",
                agent_name="agent_name",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            namespace_slug, agent_name, branch=branch, status=status, limit=limit, request_options=request_options
        )
        return _response.data
