# 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 .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,
        branch_id: str,
        *,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> VersionListResponse:
        """
        List all versions for a branch.

            Versions are ordered by deployed_at descending (most recent first).
            Each version represents a git commit that was deployed.

        Parameters
        ----------
        branch_id : str

        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.branches.versions.list(
            branch_id="branch_id",
        )
        """
        _response = self._raw_client.list(branch_id, 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,
        branch_id: str,
        *,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> VersionListResponse:
        """
        List all versions for a branch.

            Versions are ordered by deployed_at descending (most recent first).
            Each version represents a git commit that was deployed.

        Parameters
        ----------
        branch_id : str

        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.branches.versions.list(
                branch_id="branch_id",
            )


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