# This file was auto-generated by Fern from our API Definition.

from __future__ import annotations

import typing

from ....core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ....core.request_options import RequestOptions
from ....types.compile_procedures_response_model import CompileProceduresResponseModel
from ....types.create_procedure_request_model import CreateProcedureRequestModel
from ....types.create_procedure_response_model import CreateProcedureResponseModel
from ....types.list_procedures_response_model import ListProceduresResponseModel
from ....types.procedure_at_version_response_model import ProcedureAtVersionResponseModel
from .raw_client import AsyncRawProceduresClient, RawProceduresClient

if typing.TYPE_CHECKING:
    from .drafts.client import AsyncDraftsClient, DraftsClient
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class ProceduresClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawProceduresClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._drafts: typing.Optional[DraftsClient] = None

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

        Returns
        -------
        RawProceduresClient
        """
        return self._raw_client

    def list(
        self, agent_id: str, branch_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ListProceduresResponseModel:
        """
        List the agent's procedures on a branch with their procedure_id, version_id, name, type, trigger, and has_draft. has_draft is true when a procedure has unpublished draft changes on this branch; its name/type/trigger then reflect that draft. Does not return procedure content -- use Get Procedure to read a procedure's body.

        Parameters
        ----------
        agent_id : str
            Agent ID to get the procedure draft from

        branch_id : str
            Branch ID to get the procedure draft from

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

        Returns
        -------
        ListProceduresResponseModel
            Successful Response

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

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

    def create(
        self,
        agent_id: str,
        branch_id: str,
        *,
        request: typing.Optional[CreateProcedureRequestModel] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateProcedureResponseModel:
        """
        Create a new procedure for the agent on a branch.

        Parameters
        ----------
        agent_id : str
            Agent ID to get the procedure draft from

        branch_id : str
            Branch ID to get the procedure draft from

        request : typing.Optional[CreateProcedureRequestModel]

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

        Returns
        -------
        CreateProcedureResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import CreateProcedureRequestModel, ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.agents.procedures.create(
            agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
            branch_id="agtbranch_0901k4aafjxxfxt93gd841r7tv5t",
            request=CreateProcedureRequestModel(),
        )
        """
        _response = self._raw_client.create(agent_id, branch_id, request=request, request_options=request_options)
        return _response.data

    def compile(
        self, agent_id: str, branch_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> CompileProceduresResponseModel:
        """
        Compile procedure drafts into a workflow.

        Parameters
        ----------
        agent_id : str
            Agent ID to get the procedure draft from

        branch_id : str
            Branch ID to get the procedure draft from

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

        Returns
        -------
        CompileProceduresResponseModel
            Successful Response

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

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

    def get(
        self,
        agent_id: str,
        branch_id: str,
        procedure_id: str,
        *,
        version_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ProcedureAtVersionResponseModel:
        """
        Retrieve a procedure at a specific version or the current branch HEAD.

        Parameters
        ----------
        agent_id : str
            Agent ID to get the procedure draft from

        branch_id : str
            Branch ID to get the procedure draft from

        procedure_id : str
            The procedure ID

        version_id : typing.Optional[str]
            The version ID to retrieve. If omitted, returns the version at branch HEAD.

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

        Returns
        -------
        ProcedureAtVersionResponseModel
            Successful Response

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

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

    def remove(
        self,
        agent_id: str,
        branch_id: str,
        procedure_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Remove a procedure from the agent's draft working set.

        Parameters
        ----------
        agent_id : str
            Agent ID to get the procedure draft from

        branch_id : str
            Branch ID to get the procedure draft from

        procedure_id : str
            The procedure ID

        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.procedures.remove(
            agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
            branch_id="agtbranch_0901k4aafjxxfxt93gd841r7tv5t",
            procedure_id="agtprc_6qbpwdq8n01bxhk44bgjy6f10ck3",
        )
        """
        _response = self._raw_client.remove(agent_id, branch_id, procedure_id, request_options=request_options)
        return _response.data

    @property
    def drafts(self):
        if self._drafts is None:
            from .drafts.client import DraftsClient  # noqa: E402

            self._drafts = DraftsClient(client_wrapper=self._client_wrapper)
        return self._drafts


class AsyncProceduresClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawProceduresClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._drafts: typing.Optional[AsyncDraftsClient] = None

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

        Returns
        -------
        AsyncRawProceduresClient
        """
        return self._raw_client

    async def list(
        self, agent_id: str, branch_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ListProceduresResponseModel:
        """
        List the agent's procedures on a branch with their procedure_id, version_id, name, type, trigger, and has_draft. has_draft is true when a procedure has unpublished draft changes on this branch; its name/type/trigger then reflect that draft. Does not return procedure content -- use Get Procedure to read a procedure's body.

        Parameters
        ----------
        agent_id : str
            Agent ID to get the procedure draft from

        branch_id : str
            Branch ID to get the procedure draft from

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

        Returns
        -------
        ListProceduresResponseModel
            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.procedures.list(
                agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
                branch_id="agtbranch_0901k4aafjxxfxt93gd841r7tv5t",
            )


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

    async def create(
        self,
        agent_id: str,
        branch_id: str,
        *,
        request: typing.Optional[CreateProcedureRequestModel] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateProcedureResponseModel:
        """
        Create a new procedure for the agent on a branch.

        Parameters
        ----------
        agent_id : str
            Agent ID to get the procedure draft from

        branch_id : str
            Branch ID to get the procedure draft from

        request : typing.Optional[CreateProcedureRequestModel]

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

        Returns
        -------
        CreateProcedureResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs, CreateProcedureRequestModel

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.agents.procedures.create(
                agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
                branch_id="agtbranch_0901k4aafjxxfxt93gd841r7tv5t",
                request=CreateProcedureRequestModel(),
            )


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

    async def compile(
        self, agent_id: str, branch_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> CompileProceduresResponseModel:
        """
        Compile procedure drafts into a workflow.

        Parameters
        ----------
        agent_id : str
            Agent ID to get the procedure draft from

        branch_id : str
            Branch ID to get the procedure draft from

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

        Returns
        -------
        CompileProceduresResponseModel
            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.procedures.compile(
                agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
                branch_id="agtbranch_0901k4aafjxxfxt93gd841r7tv5t",
            )


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

    async def get(
        self,
        agent_id: str,
        branch_id: str,
        procedure_id: str,
        *,
        version_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ProcedureAtVersionResponseModel:
        """
        Retrieve a procedure at a specific version or the current branch HEAD.

        Parameters
        ----------
        agent_id : str
            Agent ID to get the procedure draft from

        branch_id : str
            Branch ID to get the procedure draft from

        procedure_id : str
            The procedure ID

        version_id : typing.Optional[str]
            The version ID to retrieve. If omitted, returns the version at branch HEAD.

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

        Returns
        -------
        ProcedureAtVersionResponseModel
            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.procedures.get(
                agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
                branch_id="agtbranch_0901k4aafjxxfxt93gd841r7tv5t",
                procedure_id="agtprc_6qbpwdq8n01bxhk44bgjy6f10ck3",
                version_id="version_id",
            )


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

    async def remove(
        self,
        agent_id: str,
        branch_id: str,
        procedure_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Remove a procedure from the agent's draft working set.

        Parameters
        ----------
        agent_id : str
            Agent ID to get the procedure draft from

        branch_id : str
            Branch ID to get the procedure draft from

        procedure_id : str
            The procedure ID

        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.procedures.remove(
                agent_id="agent_3701k3ttaq12ewp8b7qv5rfyszkz",
                branch_id="agtbranch_0901k4aafjxxfxt93gd841r7tv5t",
                procedure_id="agtprc_6qbpwdq8n01bxhk44bgjy6f10ck3",
            )


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

    @property
    def drafts(self):
        if self._drafts is None:
            from .drafts.client import AsyncDraftsClient  # noqa: E402

            self._drafts = AsyncDraftsClient(client_wrapper=self._client_wrapper)
        return self._drafts
