# 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_branch_response import AgentBranchResponse
from ....types.agent_workflow_request_model import AgentWorkflowRequestModel
from ....types.branch_protection_status import BranchProtectionStatus
from ....types.create_agent_branch_response_model import CreateAgentBranchResponseModel
from ....types.list_response_agent_branch_summary import ListResponseAgentBranchSummary
from .raw_client import AsyncRawBranchesClient, RawBranchesClient

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


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,
        agent_id: str,
        *,
        include_archived: typing.Optional[bool] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListResponseAgentBranchSummary:
        """
        Returns a list of branches an agent has

        Parameters
        ----------
        agent_id : str
            The id of an agent. This is returned on agent creation.

        include_archived : typing.Optional[bool]
            Whether archived branches should be included

        limit : typing.Optional[int]
            How many results at most should be returned

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

        Returns
        -------
        ListResponseAgentBranchSummary
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.agents.branches.list(
            agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
            include_archived=True,
            limit=1,
        )
        """
        _response = self._raw_client.list(
            agent_id, include_archived=include_archived, limit=limit, request_options=request_options
        )
        return _response.data

    def create(
        self,
        agent_id: str,
        *,
        parent_version_id: str,
        name: str,
        description: str,
        conversation_config: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        platform_settings: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        workflow: typing.Optional[AgentWorkflowRequestModel] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateAgentBranchResponseModel:
        """
        Create a new branch from a given version of main branch

        Parameters
        ----------
        agent_id : str
            The id of an agent. This is returned on agent creation.

        parent_version_id : str
            ID of the version to branch from

        name : str
            Name of the branch. It is unique within the agent.

        description : str
            Description for the branch

        conversation_config : typing.Optional[typing.Dict[str, typing.Any]]
            Changes to apply to conversation config

        platform_settings : typing.Optional[typing.Dict[str, typing.Any]]
            Changes to apply to platform settings

        workflow : typing.Optional[AgentWorkflowRequestModel]
            Updated workflow definition

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

        Returns
        -------
        CreateAgentBranchResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.agents.branches.create(
            agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
            parent_version_id="parent_version_id",
            name="name",
            description="description",
        )
        """
        _response = self._raw_client.create(
            agent_id,
            parent_version_id=parent_version_id,
            name=name,
            description=description,
            conversation_config=conversation_config,
            platform_settings=platform_settings,
            workflow=workflow,
            request_options=request_options,
        )
        return _response.data

    def get(
        self, agent_id: str, branch_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AgentBranchResponse:
        """
        Get information about a single agent branch

        Parameters
        ----------
        agent_id : str
            The id of an agent. This is returned on agent creation.

        branch_id : str
            Unique identifier for the branch.

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

        Returns
        -------
        AgentBranchResponse
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.agents.branches.get(
            agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
            branch_id="agtbranch_0901k4aafjxxfxt93gd841r7tv5t",
        )
        """
        _response = self._raw_client.get(agent_id, branch_id, request_options=request_options)
        return _response.data

    def update(
        self,
        agent_id: str,
        branch_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        is_archived: typing.Optional[bool] = OMIT,
        protection_status: typing.Optional[BranchProtectionStatus] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AgentBranchResponse:
        """
        Update agent branch properties such as archiving status and protection level

        Parameters
        ----------
        agent_id : str
            The id of an agent. This is returned on agent creation.

        branch_id : str
            Unique identifier for the branch.

        name : typing.Optional[str]
            New name for the branch. Must be unique within the agent.

        is_archived : typing.Optional[bool]
            Whether the branch should be archived

        protection_status : typing.Optional[BranchProtectionStatus]
            The protection level for the branch

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

        Returns
        -------
        AgentBranchResponse
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.agents.branches.update(
            agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
            branch_id="agtbranch_0901k4aafjxxfxt93gd841r7tv5t",
        )
        """
        _response = self._raw_client.update(
            agent_id,
            branch_id,
            name=name,
            is_archived=is_archived,
            protection_status=protection_status,
            request_options=request_options,
        )
        return _response.data

    def merge(
        self,
        agent_id: str,
        source_branch_id: str,
        *,
        target_branch_id: str,
        archive_source_branch: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Merge a branch into a target branch

        Parameters
        ----------
        agent_id : str
            The id of an agent. This is returned on agent creation.

        source_branch_id : str
            Unique identifier for the source branch to merge from.

        target_branch_id : str
            The ID of the target branch to merge into (must be the main branch).

        archive_source_branch : typing.Optional[bool]
            Whether to archive the source branch after merging

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

        Returns
        -------
        typing.Any
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.agents.branches.merge(
            agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
            source_branch_id="agtbrch_8901k4t9z5defmb8vh3e9361y7nj",
            target_branch_id="agtbrch_8901k4t9z5defmb8vh3e9361y7nj",
        )
        """
        _response = self._raw_client.merge(
            agent_id,
            source_branch_id,
            target_branch_id=target_branch_id,
            archive_source_branch=archive_source_branch,
            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,
        agent_id: str,
        *,
        include_archived: typing.Optional[bool] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListResponseAgentBranchSummary:
        """
        Returns a list of branches an agent has

        Parameters
        ----------
        agent_id : str
            The id of an agent. This is returned on agent creation.

        include_archived : typing.Optional[bool]
            Whether archived branches should be included

        limit : typing.Optional[int]
            How many results at most should be returned

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

        Returns
        -------
        ListResponseAgentBranchSummary
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.agents.branches.list(
                agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
                include_archived=True,
                limit=1,
            )


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

    async def create(
        self,
        agent_id: str,
        *,
        parent_version_id: str,
        name: str,
        description: str,
        conversation_config: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        platform_settings: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        workflow: typing.Optional[AgentWorkflowRequestModel] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateAgentBranchResponseModel:
        """
        Create a new branch from a given version of main branch

        Parameters
        ----------
        agent_id : str
            The id of an agent. This is returned on agent creation.

        parent_version_id : str
            ID of the version to branch from

        name : str
            Name of the branch. It is unique within the agent.

        description : str
            Description for the branch

        conversation_config : typing.Optional[typing.Dict[str, typing.Any]]
            Changes to apply to conversation config

        platform_settings : typing.Optional[typing.Dict[str, typing.Any]]
            Changes to apply to platform settings

        workflow : typing.Optional[AgentWorkflowRequestModel]
            Updated workflow definition

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

        Returns
        -------
        CreateAgentBranchResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.agents.branches.create(
                agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
                parent_version_id="parent_version_id",
                name="name",
                description="description",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            agent_id,
            parent_version_id=parent_version_id,
            name=name,
            description=description,
            conversation_config=conversation_config,
            platform_settings=platform_settings,
            workflow=workflow,
            request_options=request_options,
        )
        return _response.data

    async def get(
        self, agent_id: str, branch_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AgentBranchResponse:
        """
        Get information about a single agent branch

        Parameters
        ----------
        agent_id : str
            The id of an agent. This is returned on agent creation.

        branch_id : str
            Unique identifier for the branch.

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

        Returns
        -------
        AgentBranchResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.agents.branches.get(
                agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
                branch_id="agtbranch_0901k4aafjxxfxt93gd841r7tv5t",
            )


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

    async def update(
        self,
        agent_id: str,
        branch_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        is_archived: typing.Optional[bool] = OMIT,
        protection_status: typing.Optional[BranchProtectionStatus] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AgentBranchResponse:
        """
        Update agent branch properties such as archiving status and protection level

        Parameters
        ----------
        agent_id : str
            The id of an agent. This is returned on agent creation.

        branch_id : str
            Unique identifier for the branch.

        name : typing.Optional[str]
            New name for the branch. Must be unique within the agent.

        is_archived : typing.Optional[bool]
            Whether the branch should be archived

        protection_status : typing.Optional[BranchProtectionStatus]
            The protection level for the branch

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

        Returns
        -------
        AgentBranchResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.agents.branches.update(
                agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
                branch_id="agtbranch_0901k4aafjxxfxt93gd841r7tv5t",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            agent_id,
            branch_id,
            name=name,
            is_archived=is_archived,
            protection_status=protection_status,
            request_options=request_options,
        )
        return _response.data

    async def merge(
        self,
        agent_id: str,
        source_branch_id: str,
        *,
        target_branch_id: str,
        archive_source_branch: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Merge a branch into a target branch

        Parameters
        ----------
        agent_id : str
            The id of an agent. This is returned on agent creation.

        source_branch_id : str
            Unique identifier for the source branch to merge from.

        target_branch_id : str
            The ID of the target branch to merge into (must be the main branch).

        archive_source_branch : typing.Optional[bool]
            Whether to archive the source branch after merging

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

        Returns
        -------
        typing.Any
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.agents.branches.merge(
                agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
                source_branch_id="agtbrch_8901k4t9z5defmb8vh3e9361y7nj",
                target_branch_id="agtbrch_8901k4t9z5defmb8vh3e9361y7nj",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.merge(
            agent_id,
            source_branch_id,
            target_branch_id=target_branch_id,
            archive_source_branch=archive_source_branch,
            request_options=request_options,
        )
        return _response.data
