# 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.branch_list_response import BranchListResponse
from .raw_client import AsyncRawBranchesClient, RawBranchesClient


class BranchesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawBranchesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawBranchesClient
        """
        return self._raw_client

    def list(
        self,
        namespace_slug: str,
        agent_name: str,
        env_name: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> BranchListResponse:
        """
        List all branches that match this environment's branch rules.

            For wildcard environments (like preview with ["*"]),
            returns all non-retired branches for the agent.

            For specific branch rules (like production with ["main"]),
            returns only the matching branch(es).

            Branches are sorted by updated_at descending (most recent first).

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

        agent_name : str

        env_name : str

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

        Returns
        -------
        BranchListResponse
            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.environments.branches.list(
            namespace_slug="namespace_slug",
            agent_name="agent_name",
            env_name="env_name",
        )
        """
        _response = self._raw_client.list(namespace_slug, agent_name, env_name, request_options=request_options)
        return _response.data


class AsyncBranchesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawBranchesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawBranchesClient
        """
        return self._raw_client

    async def list(
        self,
        namespace_slug: str,
        agent_name: str,
        env_name: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> BranchListResponse:
        """
        List all branches that match this environment's branch rules.

            For wildcard environments (like preview with ["*"]),
            returns all non-retired branches for the agent.

            For specific branch rules (like production with ["main"]),
            returns only the matching branch(es).

            Branches are sorted by updated_at descending (most recent first).

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

        agent_name : str

        env_name : str

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

        Returns
        -------
        BranchListResponse
            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.environments.branches.list(
                namespace_slug="namespace_slug",
                agent_name="agent_name",
                env_name="env_name",
            )


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