# 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.run_task_response import RunTaskResponse
from .raw_client import AsyncRawTasksClient, RawTasksClient
from .types.run_task_request_task_type import RunTaskRequestTaskType

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


class TasksClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawTasksClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawTasksClient
        """
        return self._raw_client

    def run_task(
        self,
        *,
        task_id: str,
        arguments: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
        task_type: typing.Optional[RunTaskRequestTaskType] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RunTaskResponse:
        """
        Run a [task](https://resources.athenaintel.com/docs/task-studio/home) and wait for the result.

        Executes a Windmill script or flow synchronously. Server handles polling internally.

        Parameters
        ----------
        task_id : str
            The unique identifier (path) of the task. Example: 'f/public/databricks_describe_table'

        arguments : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
            Arguments to pass to the task

        task_type : typing.Optional[RunTaskRequestTaskType]
            Type: 'script' or 'flow'

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

        Returns
        -------
        RunTaskResponse
            Successful Response

        Examples
        --------
        from athena import Athena

        client = Athena(
            api_key="YOUR_API_KEY",
        )
        client.tools.tasks.run_task(
            task_id="task_id",
        )
        """
        _response = self._raw_client.run_task(
            task_id=task_id, arguments=arguments, task_type=task_type, request_options=request_options
        )
        return _response.data


class AsyncTasksClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawTasksClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawTasksClient
        """
        return self._raw_client

    async def run_task(
        self,
        *,
        task_id: str,
        arguments: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
        task_type: typing.Optional[RunTaskRequestTaskType] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RunTaskResponse:
        """
        Run a [task](https://resources.athenaintel.com/docs/task-studio/home) and wait for the result.

        Executes a Windmill script or flow synchronously. Server handles polling internally.

        Parameters
        ----------
        task_id : str
            The unique identifier (path) of the task. Example: 'f/public/databricks_describe_table'

        arguments : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
            Arguments to pass to the task

        task_type : typing.Optional[RunTaskRequestTaskType]
            Type: 'script' or 'flow'

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

        Returns
        -------
        RunTaskResponse
            Successful Response

        Examples
        --------
        import asyncio

        from athena import AsyncAthena

        client = AsyncAthena(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.tools.tasks.run_task(
                task_id="task_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.run_task(
            task_id=task_id, arguments=arguments, task_type=task_type, request_options=request_options
        )
        return _response.data
