# 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 .raw_client import AsyncRawWorkflowsClient, RawWorkflowsClient
from .types.create_workflow_request_fhir_provider_id import CreateWorkflowRequestFhirProviderId
from .types.create_workflow_response import CreateWorkflowResponse
from .types.execute_workflow_response import ExecuteWorkflowResponse
from .types.list_workflows_response import ListWorkflowsResponse
from .types.update_workflow_request_fhir_provider_id import UpdateWorkflowRequestFhirProviderId
from .types.workflows_delete_response import WorkflowsDeleteResponse
from .types.workflows_get_response import WorkflowsGetResponse
from .types.workflows_update_response import WorkflowsUpdateResponse

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


class WorkflowsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawWorkflowsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawWorkflowsClient
        """
        return self._raw_client

    def list(
        self, *, verbose: typing.Optional[bool] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> ListWorkflowsResponse:
        """
        Retrieves all workflow definitions for the authenticated user

        Parameters
        ----------
        verbose : typing.Optional[bool]
            If true, includes full workflow implementation details in workflow_details field

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

        Returns
        -------
        ListWorkflowsResponse
            Successfully retrieved workflows

        Examples
        --------
        from phenoml import phenoml

        client = phenoml(
            token="YOUR_TOKEN",
        )
        client.workflows.list(
            verbose=True,
        )
        """
        _response = self._raw_client.list(verbose=verbose, request_options=request_options)
        return _response.data

    def create(
        self,
        *,
        name: str,
        workflow_instructions: str,
        sample_data: typing.Dict[str, typing.Optional[typing.Any]],
        fhir_provider_id: CreateWorkflowRequestFhirProviderId,
        verbose: typing.Optional[bool] = None,
        dynamic_generation: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateWorkflowResponse:
        """
        Creates a new workflow definition with graph generation from workflow instructions

        Parameters
        ----------
        name : str
            Human-readable name for the workflow

        workflow_instructions : str
            Natural language instructions that define the workflow logic

        sample_data : typing.Dict[str, typing.Optional[typing.Any]]
            Sample data to use for workflow graph generation

        fhir_provider_id : CreateWorkflowRequestFhirProviderId
            FHIR provider ID(s) - must be valid UUID(s) from existing FHIR providers

        verbose : typing.Optional[bool]
            If true, includes full workflow implementation details in workflow_details field

        dynamic_generation : typing.Optional[bool]
            Enable dynamic lang2fhir calls instead of pre-populated templates

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

        Returns
        -------
        CreateWorkflowResponse
            Successfully created workflow

        Examples
        --------
        from phenoml import phenoml

        client = phenoml(
            token="YOUR_TOKEN",
        )
        client.workflows.create(
            verbose=True,
            name="Patient Data Mapping Workflow",
            workflow_instructions="Given diagnosis data, find the patient and create condition record",
            sample_data={
                "patient_last_name": "Rippin",
                "patient_first_name": "Clay",
                "diagnosis_code": "I10",
            },
            fhir_provider_id="550e8400-e29b-41d4-a716-446655440000",
        )
        """
        _response = self._raw_client.create(
            name=name,
            workflow_instructions=workflow_instructions,
            sample_data=sample_data,
            fhir_provider_id=fhir_provider_id,
            verbose=verbose,
            dynamic_generation=dynamic_generation,
            request_options=request_options,
        )
        return _response.data

    def get(
        self, id: str, *, verbose: typing.Optional[bool] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> WorkflowsGetResponse:
        """
        Retrieves a workflow definition by its ID

        Parameters
        ----------
        id : str
            ID of the workflow to retrieve

        verbose : typing.Optional[bool]
            If true, includes full workflow implementation details in workflow_details field

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

        Returns
        -------
        WorkflowsGetResponse
            Successfully retrieved workflow

        Examples
        --------
        from phenoml import phenoml

        client = phenoml(
            token="YOUR_TOKEN",
        )
        client.workflows.get(
            id="id",
            verbose=True,
        )
        """
        _response = self._raw_client.get(id, verbose=verbose, request_options=request_options)
        return _response.data

    def update(
        self,
        id: str,
        *,
        name: str,
        workflow_instructions: str,
        sample_data: typing.Dict[str, typing.Optional[typing.Any]],
        fhir_provider_id: UpdateWorkflowRequestFhirProviderId,
        verbose: typing.Optional[bool] = None,
        dynamic_generation: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WorkflowsUpdateResponse:
        """
        Updates an existing workflow definition

        Parameters
        ----------
        id : str
            ID of the workflow to update

        name : str
            Human-readable name for the workflow

        workflow_instructions : str
            Natural language instructions that define the workflow logic

        sample_data : typing.Dict[str, typing.Optional[typing.Any]]
            Sample data to use for workflow graph generation

        fhir_provider_id : UpdateWorkflowRequestFhirProviderId
            FHIR provider ID(s) - must be valid UUID(s) from existing FHIR providers

        verbose : typing.Optional[bool]
            If true, includes full workflow implementation details in workflow_details field

        dynamic_generation : typing.Optional[bool]
            Enable dynamic lang2fhir calls instead of pre-populated templates

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

        Returns
        -------
        WorkflowsUpdateResponse
            Successfully updated workflow

        Examples
        --------
        from phenoml import phenoml

        client = phenoml(
            token="YOUR_TOKEN",
        )
        client.workflows.update(
            id="id",
            verbose=True,
            name="Updated Patient Data Mapping Workflow",
            workflow_instructions="Given diagnosis data, find the patient and create condition record",
            sample_data={
                "patient_last_name": "Smith",
                "patient_first_name": "John",
                "diagnosis_code": "E11",
            },
            fhir_provider_id="550e8400-e29b-41d4-a716-446655440000",
        )
        """
        _response = self._raw_client.update(
            id,
            name=name,
            workflow_instructions=workflow_instructions,
            sample_data=sample_data,
            fhir_provider_id=fhir_provider_id,
            verbose=verbose,
            dynamic_generation=dynamic_generation,
            request_options=request_options,
        )
        return _response.data

    def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> WorkflowsDeleteResponse:
        """
        Deletes a workflow definition by its ID

        Parameters
        ----------
        id : str
            ID of the workflow to delete

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

        Returns
        -------
        WorkflowsDeleteResponse
            Successfully deleted workflow

        Examples
        --------
        from phenoml import phenoml

        client = phenoml(
            token="YOUR_TOKEN",
        )
        client.workflows.delete(
            id="id",
        )
        """
        _response = self._raw_client.delete(id, request_options=request_options)
        return _response.data

    def execute(
        self,
        id: str,
        *,
        input_data: typing.Dict[str, typing.Optional[typing.Any]],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExecuteWorkflowResponse:
        """
        Executes a workflow with provided input data and returns results

        Parameters
        ----------
        id : str
            ID of the workflow to execute

        input_data : typing.Dict[str, typing.Optional[typing.Any]]
            Input data for workflow execution

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

        Returns
        -------
        ExecuteWorkflowResponse
            Successfully executed workflow

        Examples
        --------
        from phenoml import phenoml

        client = phenoml(
            token="YOUR_TOKEN",
        )
        client.workflows.execute(
            id="id",
            input_data={
                "patient_last_name": "Johnson",
                "patient_first_name": "Mary",
                "diagnosis_code": "M79.3",
                "encounter_date": "2024-01-15",
            },
        )
        """
        _response = self._raw_client.execute(id, input_data=input_data, request_options=request_options)
        return _response.data


class AsyncWorkflowsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawWorkflowsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawWorkflowsClient
        """
        return self._raw_client

    async def list(
        self, *, verbose: typing.Optional[bool] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> ListWorkflowsResponse:
        """
        Retrieves all workflow definitions for the authenticated user

        Parameters
        ----------
        verbose : typing.Optional[bool]
            If true, includes full workflow implementation details in workflow_details field

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

        Returns
        -------
        ListWorkflowsResponse
            Successfully retrieved workflows

        Examples
        --------
        import asyncio

        from phenoml import Asyncphenoml

        client = Asyncphenoml(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.workflows.list(
                verbose=True,
            )


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

    async def create(
        self,
        *,
        name: str,
        workflow_instructions: str,
        sample_data: typing.Dict[str, typing.Optional[typing.Any]],
        fhir_provider_id: CreateWorkflowRequestFhirProviderId,
        verbose: typing.Optional[bool] = None,
        dynamic_generation: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateWorkflowResponse:
        """
        Creates a new workflow definition with graph generation from workflow instructions

        Parameters
        ----------
        name : str
            Human-readable name for the workflow

        workflow_instructions : str
            Natural language instructions that define the workflow logic

        sample_data : typing.Dict[str, typing.Optional[typing.Any]]
            Sample data to use for workflow graph generation

        fhir_provider_id : CreateWorkflowRequestFhirProviderId
            FHIR provider ID(s) - must be valid UUID(s) from existing FHIR providers

        verbose : typing.Optional[bool]
            If true, includes full workflow implementation details in workflow_details field

        dynamic_generation : typing.Optional[bool]
            Enable dynamic lang2fhir calls instead of pre-populated templates

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

        Returns
        -------
        CreateWorkflowResponse
            Successfully created workflow

        Examples
        --------
        import asyncio

        from phenoml import Asyncphenoml

        client = Asyncphenoml(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.workflows.create(
                verbose=True,
                name="Patient Data Mapping Workflow",
                workflow_instructions="Given diagnosis data, find the patient and create condition record",
                sample_data={
                    "patient_last_name": "Rippin",
                    "patient_first_name": "Clay",
                    "diagnosis_code": "I10",
                },
                fhir_provider_id="550e8400-e29b-41d4-a716-446655440000",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            name=name,
            workflow_instructions=workflow_instructions,
            sample_data=sample_data,
            fhir_provider_id=fhir_provider_id,
            verbose=verbose,
            dynamic_generation=dynamic_generation,
            request_options=request_options,
        )
        return _response.data

    async def get(
        self, id: str, *, verbose: typing.Optional[bool] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> WorkflowsGetResponse:
        """
        Retrieves a workflow definition by its ID

        Parameters
        ----------
        id : str
            ID of the workflow to retrieve

        verbose : typing.Optional[bool]
            If true, includes full workflow implementation details in workflow_details field

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

        Returns
        -------
        WorkflowsGetResponse
            Successfully retrieved workflow

        Examples
        --------
        import asyncio

        from phenoml import Asyncphenoml

        client = Asyncphenoml(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.workflows.get(
                id="id",
                verbose=True,
            )


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

    async def update(
        self,
        id: str,
        *,
        name: str,
        workflow_instructions: str,
        sample_data: typing.Dict[str, typing.Optional[typing.Any]],
        fhir_provider_id: UpdateWorkflowRequestFhirProviderId,
        verbose: typing.Optional[bool] = None,
        dynamic_generation: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WorkflowsUpdateResponse:
        """
        Updates an existing workflow definition

        Parameters
        ----------
        id : str
            ID of the workflow to update

        name : str
            Human-readable name for the workflow

        workflow_instructions : str
            Natural language instructions that define the workflow logic

        sample_data : typing.Dict[str, typing.Optional[typing.Any]]
            Sample data to use for workflow graph generation

        fhir_provider_id : UpdateWorkflowRequestFhirProviderId
            FHIR provider ID(s) - must be valid UUID(s) from existing FHIR providers

        verbose : typing.Optional[bool]
            If true, includes full workflow implementation details in workflow_details field

        dynamic_generation : typing.Optional[bool]
            Enable dynamic lang2fhir calls instead of pre-populated templates

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

        Returns
        -------
        WorkflowsUpdateResponse
            Successfully updated workflow

        Examples
        --------
        import asyncio

        from phenoml import Asyncphenoml

        client = Asyncphenoml(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.workflows.update(
                id="id",
                verbose=True,
                name="Updated Patient Data Mapping Workflow",
                workflow_instructions="Given diagnosis data, find the patient and create condition record",
                sample_data={
                    "patient_last_name": "Smith",
                    "patient_first_name": "John",
                    "diagnosis_code": "E11",
                },
                fhir_provider_id="550e8400-e29b-41d4-a716-446655440000",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            id,
            name=name,
            workflow_instructions=workflow_instructions,
            sample_data=sample_data,
            fhir_provider_id=fhir_provider_id,
            verbose=verbose,
            dynamic_generation=dynamic_generation,
            request_options=request_options,
        )
        return _response.data

    async def delete(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> WorkflowsDeleteResponse:
        """
        Deletes a workflow definition by its ID

        Parameters
        ----------
        id : str
            ID of the workflow to delete

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

        Returns
        -------
        WorkflowsDeleteResponse
            Successfully deleted workflow

        Examples
        --------
        import asyncio

        from phenoml import Asyncphenoml

        client = Asyncphenoml(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.workflows.delete(
                id="id",
            )


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

    async def execute(
        self,
        id: str,
        *,
        input_data: typing.Dict[str, typing.Optional[typing.Any]],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExecuteWorkflowResponse:
        """
        Executes a workflow with provided input data and returns results

        Parameters
        ----------
        id : str
            ID of the workflow to execute

        input_data : typing.Dict[str, typing.Optional[typing.Any]]
            Input data for workflow execution

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

        Returns
        -------
        ExecuteWorkflowResponse
            Successfully executed workflow

        Examples
        --------
        import asyncio

        from phenoml import Asyncphenoml

        client = Asyncphenoml(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.workflows.execute(
                id="id",
                input_data={
                    "patient_last_name": "Johnson",
                    "patient_first_name": "Mary",
                    "diagnosis_code": "M79.3",
                    "encounter_date": "2024-01-15",
                },
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.execute(id, input_data=input_data, request_options=request_options)
        return _response.data
