# 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_workflow_request_model import AgentWorkflowRequestModel
from .raw_client import AsyncRawDraftsClient, RawDraftsClient

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


class DraftsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawDraftsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawDraftsClient
        """
        return self._raw_client

    def create(
        self,
        agent_id: str,
        *,
        branch_id: str,
        conversation_config: typing.Dict[str, typing.Any],
        platform_settings: typing.Dict[str, typing.Any],
        workflow: AgentWorkflowRequestModel,
        name: str,
        tags: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Create a new draft for an agent

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

        branch_id : str
            The ID of the agent branch to use

        conversation_config : typing.Dict[str, typing.Any]
            Conversation config for the draft

        platform_settings : typing.Dict[str, typing.Any]
            Platform settings for the draft

        workflow : AgentWorkflowRequestModel
            Workflow for the draft

        name : str
            Name for the draft

        tags : typing.Optional[typing.Sequence[str]]
            Tags to help classify and filter the agent

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

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

        Examples
        --------
        from elevenlabs import (
            AgentWorkflowRequestModel,
            AgentWorkflowRequestModelNodesValue_End,
            AstNodeInput_AndOperator,
            ElevenLabs,
            WorkflowEdgeModelInput,
            WorkflowEdgeModelInputForwardCondition_Expression,
        )

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.agents.drafts.create(
            agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
            branch_id="agtbrch_8901k4t9z5defmb8vh3e9361y7nj",
            conversation_config={"key": "value"},
            platform_settings={"key": "value"},
            workflow=AgentWorkflowRequestModel(
                edges={
                    "entry_to_tool_a": WorkflowEdgeModelInput(
                        source="entry_node",
                        target="tool_node_a",
                        forward_condition=WorkflowEdgeModelInputForwardCondition_Expression(
                            expression=AstNodeInput_AndOperator(
                                children=[],
                            ),
                        ),
                    ),
                    "start_to_entry": WorkflowEdgeModelInput(
                        source="start_node",
                        target="entry_node",
                        forward_condition=WorkflowEdgeModelInputForwardCondition_Expression(
                            expression=AstNodeInput_AndOperator(
                                children=[],
                            ),
                        ),
                    ),
                    "tool_a_to_failure": WorkflowEdgeModelInput(
                        source="tool_node_a",
                        target="failure_node",
                        forward_condition=WorkflowEdgeModelInputForwardCondition_Expression(
                            expression=AstNodeInput_AndOperator(
                                children=[],
                            ),
                        ),
                    ),
                    "tool_a_to_tool_b": WorkflowEdgeModelInput(
                        source="tool_node_a",
                        target="tool_node_b",
                        forward_condition=WorkflowEdgeModelInputForwardCondition_Expression(
                            expression=AstNodeInput_AndOperator(
                                children=[],
                            ),
                        ),
                    ),
                    "tool_b_to_agent_transfer": WorkflowEdgeModelInput(
                        source="tool_node_b",
                        target="success_transfer",
                        forward_condition=WorkflowEdgeModelInputForwardCondition_Expression(
                            expression=AstNodeInput_AndOperator(
                                children=[],
                            ),
                        ),
                    ),
                    "tool_b_to_conversation": WorkflowEdgeModelInput(
                        source="tool_node_b",
                        target="success_conversation",
                        forward_condition=WorkflowEdgeModelInputForwardCondition_Expression(
                            expression=AstNodeInput_AndOperator(
                                children=[],
                            ),
                        ),
                    ),
                    "tool_b_to_end": WorkflowEdgeModelInput(
                        source="tool_node_b",
                        target="success_end",
                        forward_condition=WorkflowEdgeModelInputForwardCondition_Expression(
                            expression=AstNodeInput_AndOperator(
                                children=[],
                            ),
                        ),
                    ),
                    "tool_b_to_phone": WorkflowEdgeModelInput(
                        source="tool_node_b",
                        target="success_phone",
                        forward_condition=WorkflowEdgeModelInputForwardCondition_Expression(
                            expression=AstNodeInput_AndOperator(
                                children=[],
                            ),
                        ),
                    ),
                },
                nodes={
                    "entry_node": AgentWorkflowRequestModelNodesValue_End(),
                    "failure_node": AgentWorkflowRequestModelNodesValue_End(),
                    "start_node": AgentWorkflowRequestModelNodesValue_End(),
                    "success_conversation": AgentWorkflowRequestModelNodesValue_End(),
                    "success_end": AgentWorkflowRequestModelNodesValue_End(),
                    "success_phone": AgentWorkflowRequestModelNodesValue_End(),
                    "success_transfer": AgentWorkflowRequestModelNodesValue_End(),
                    "tool_node_a": AgentWorkflowRequestModelNodesValue_End(),
                    "tool_node_b": AgentWorkflowRequestModelNodesValue_End(),
                },
            ),
            name="name",
        )
        """
        _response = self._raw_client.create(
            agent_id,
            branch_id=branch_id,
            conversation_config=conversation_config,
            platform_settings=platform_settings,
            workflow=workflow,
            name=name,
            tags=tags,
            request_options=request_options,
        )
        return _response.data

    def delete(
        self, agent_id: str, *, branch_id: str, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Any:
        """
        Delete a draft for an agent

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

        branch_id : str
            The ID of the agent branch to use

        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.drafts.delete(
            agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
            branch_id="agtbrch_8901k4t9z5defmb8vh3e9361y7nj",
        )
        """
        _response = self._raw_client.delete(agent_id, branch_id=branch_id, request_options=request_options)
        return _response.data


class AsyncDraftsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawDraftsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawDraftsClient
        """
        return self._raw_client

    async def create(
        self,
        agent_id: str,
        *,
        branch_id: str,
        conversation_config: typing.Dict[str, typing.Any],
        platform_settings: typing.Dict[str, typing.Any],
        workflow: AgentWorkflowRequestModel,
        name: str,
        tags: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Create a new draft for an agent

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

        branch_id : str
            The ID of the agent branch to use

        conversation_config : typing.Dict[str, typing.Any]
            Conversation config for the draft

        platform_settings : typing.Dict[str, typing.Any]
            Platform settings for the draft

        workflow : AgentWorkflowRequestModel
            Workflow for the draft

        name : str
            Name for the draft

        tags : typing.Optional[typing.Sequence[str]]
            Tags to help classify and filter the agent

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

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

        Examples
        --------
        import asyncio

        from elevenlabs import (
            AgentWorkflowRequestModel,
            AgentWorkflowRequestModelNodesValue_End,
            AstNodeInput_AndOperator,
            AsyncElevenLabs,
            WorkflowEdgeModelInput,
            WorkflowEdgeModelInputForwardCondition_Expression,
        )

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.agents.drafts.create(
                agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
                branch_id="agtbrch_8901k4t9z5defmb8vh3e9361y7nj",
                conversation_config={"key": "value"},
                platform_settings={"key": "value"},
                workflow=AgentWorkflowRequestModel(
                    edges={
                        "entry_to_tool_a": WorkflowEdgeModelInput(
                            source="entry_node",
                            target="tool_node_a",
                            forward_condition=WorkflowEdgeModelInputForwardCondition_Expression(
                                expression=AstNodeInput_AndOperator(
                                    children=[],
                                ),
                            ),
                        ),
                        "start_to_entry": WorkflowEdgeModelInput(
                            source="start_node",
                            target="entry_node",
                            forward_condition=WorkflowEdgeModelInputForwardCondition_Expression(
                                expression=AstNodeInput_AndOperator(
                                    children=[],
                                ),
                            ),
                        ),
                        "tool_a_to_failure": WorkflowEdgeModelInput(
                            source="tool_node_a",
                            target="failure_node",
                            forward_condition=WorkflowEdgeModelInputForwardCondition_Expression(
                                expression=AstNodeInput_AndOperator(
                                    children=[],
                                ),
                            ),
                        ),
                        "tool_a_to_tool_b": WorkflowEdgeModelInput(
                            source="tool_node_a",
                            target="tool_node_b",
                            forward_condition=WorkflowEdgeModelInputForwardCondition_Expression(
                                expression=AstNodeInput_AndOperator(
                                    children=[],
                                ),
                            ),
                        ),
                        "tool_b_to_agent_transfer": WorkflowEdgeModelInput(
                            source="tool_node_b",
                            target="success_transfer",
                            forward_condition=WorkflowEdgeModelInputForwardCondition_Expression(
                                expression=AstNodeInput_AndOperator(
                                    children=[],
                                ),
                            ),
                        ),
                        "tool_b_to_conversation": WorkflowEdgeModelInput(
                            source="tool_node_b",
                            target="success_conversation",
                            forward_condition=WorkflowEdgeModelInputForwardCondition_Expression(
                                expression=AstNodeInput_AndOperator(
                                    children=[],
                                ),
                            ),
                        ),
                        "tool_b_to_end": WorkflowEdgeModelInput(
                            source="tool_node_b",
                            target="success_end",
                            forward_condition=WorkflowEdgeModelInputForwardCondition_Expression(
                                expression=AstNodeInput_AndOperator(
                                    children=[],
                                ),
                            ),
                        ),
                        "tool_b_to_phone": WorkflowEdgeModelInput(
                            source="tool_node_b",
                            target="success_phone",
                            forward_condition=WorkflowEdgeModelInputForwardCondition_Expression(
                                expression=AstNodeInput_AndOperator(
                                    children=[],
                                ),
                            ),
                        ),
                    },
                    nodes={
                        "entry_node": AgentWorkflowRequestModelNodesValue_End(),
                        "failure_node": AgentWorkflowRequestModelNodesValue_End(),
                        "start_node": AgentWorkflowRequestModelNodesValue_End(),
                        "success_conversation": AgentWorkflowRequestModelNodesValue_End(),
                        "success_end": AgentWorkflowRequestModelNodesValue_End(),
                        "success_phone": AgentWorkflowRequestModelNodesValue_End(),
                        "success_transfer": AgentWorkflowRequestModelNodesValue_End(),
                        "tool_node_a": AgentWorkflowRequestModelNodesValue_End(),
                        "tool_node_b": AgentWorkflowRequestModelNodesValue_End(),
                    },
                ),
                name="name",
            )


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

    async def delete(
        self, agent_id: str, *, branch_id: str, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Any:
        """
        Delete a draft for an agent

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

        branch_id : str
            The ID of the agent branch to use

        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.drafts.delete(
                agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
                branch_id="agtbrch_8901k4t9z5defmb8vh3e9361y7nj",
            )


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