# 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.analyze_max_tokens import AnalyzeMaxTokens
from ...types.analyze_task_response import AnalyzeTaskResponse
from ...types.analyze_task_status import AnalyzeTaskStatus
from ...types.analyze_temperature import AnalyzeTemperature
from ...types.analyze_text_prompt import AnalyzeTextPrompt
from ...types.create_analyze_task_response import CreateAnalyzeTaskResponse
from ...types.response_format import ResponseFormat
from ...types.video_context import VideoContext
from .raw_client import AsyncRawTasksClient, RawTasksClient
from .types.tasks_list_response import TasksListResponse

# 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 list(
        self,
        *,
        page: typing.Optional[int] = None,
        page_limit: typing.Optional[int] = None,
        status: typing.Optional[AnalyzeTaskStatus] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TasksListResponse:
        """
        This method returns a list of the analysis tasks in your account. The platform returns your analysis tasks sorted by creation date, with the newest at the top of the list.

        Parameters
        ----------
        page : typing.Optional[int]
            A number that identifies the page to retrieve.

            **Default**: `1`.

        page_limit : typing.Optional[int]
            The number of items to return on each page.

            **Default**: `10`.
            **Max**: `50`.

        status : typing.Optional[AnalyzeTaskStatus]
            Filter analysis tasks by status.
            Possible values: `queued`, `pending`, `processing`, `ready`, `failed`.

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

        Returns
        -------
        TasksListResponse
            A list of analysis tasks has successfully been retrieved.

        Examples
        --------
        from twelvelabs import TwelveLabs

        client = TwelveLabs(
            api_key="YOUR_API_KEY",
        )
        client.analyze_async.tasks.list(
            page=1,
            page_limit=10,
            status="queued",
        )
        """
        _response = self._raw_client.list(
            page=page, page_limit=page_limit, status=status, request_options=request_options
        )
        return _response.data

    def create(
        self,
        *,
        video: VideoContext,
        prompt: AnalyzeTextPrompt,
        temperature: typing.Optional[AnalyzeTemperature] = OMIT,
        max_tokens: typing.Optional[AnalyzeMaxTokens] = OMIT,
        response_format: typing.Optional[ResponseFormat] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateAnalyzeTaskResponse:
        """
        This method asynchronously analyzes your videos and generates fully customizable text based on your prompts.

        <Accordion title="Input requirements">
        - Minimum duration: 4 seconds
        - Maximum duration: 2 hours
        - Formats: [FFmpeg supported formats](https://ffmpeg.org/ffmpeg-formats.html)
        - Resolution: 360x360 to 5184x2160 pixels
        - Aspect ratio: Between 1:1 and 1:2.4, or between 2.4:1 and 1:1.
        </Accordion>

        **When to use this method**:
        - Analyze videos longer than 1 hour
        - Process videos asynchronously without blocking your application

        **Do not use this method for**:
        - Videos for which you need immediate results or real-time streaming. Use the [`POST`](/v1.3/api-reference/analyze-videos/sync-analysis) method of the `/analyze` endpoint instead.

        Analyzing videos asynchronously requires three steps:

        1. Create an analysis task using this method. The platform returns a task ID.
        2. Poll the status of the task using the [`GET`](/v1.3/api-reference/analyze-videos/retrieve-analysis-task-status-results) method of the `/analyze/tasks/{task_id}` endpoint. Wait until the status is `ready`.
        3. Retrieve the results from the response when the status is `ready` using the [`GET`](/v1.3/api-reference/analyze-videos/retrieve-analysis-task-status-results) method of the `/analyze/tasks/{task_id}` endpoint.

        <Note title="Note">
        This endpoint is rate-limited. For details, see the [Rate limits](/v1.3/docs/get-started/rate-limits) page.
        </Note>

        Parameters
        ----------
        video : VideoContext

        prompt : AnalyzeTextPrompt

        temperature : typing.Optional[AnalyzeTemperature]

        max_tokens : typing.Optional[AnalyzeMaxTokens]

        response_format : typing.Optional[ResponseFormat]

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

        Returns
        -------
        CreateAnalyzeTaskResponse
            An analysis task has successfully been created.

        Examples
        --------
        from twelvelabs import TwelveLabs, VideoContext_Url

        client = TwelveLabs(
            api_key="YOUR_API_KEY",
        )
        client.analyze_async.tasks.create(
            video=VideoContext_Url(
                url="https://example.com/video.mp4",
            ),
            prompt="Generate a detailed summary of this video in 3-4 sentences",
            temperature=0.2,
            max_tokens=1000,
        )
        """
        _response = self._raw_client.create(
            video=video,
            prompt=prompt,
            temperature=temperature,
            max_tokens=max_tokens,
            response_format=response_format,
            request_options=request_options,
        )
        return _response.data

    def retrieve(self, task_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> AnalyzeTaskResponse:
        """
        This method retrieves the status and results of an analysis task.

        **Task statuses**:
        - `queued`: The task is waiting to be processed.
        - `pending`: The task is queued and waiting to start.
        - `processing`: The platform is analyzing the video.
        - `ready`: Processing is complete. Results are available in the response.
        - `failed`: The task failed. No results were generated.

        Poll this method until `status` is `ready` or `failed`. When `status` is `ready`, use the results from the response.

        Parameters
        ----------
        task_id : str
            The unique identifier of the analysis task.

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

        Returns
        -------
        AnalyzeTaskResponse
            Task status and results retrieved successfully

        Examples
        --------
        from twelvelabs import TwelveLabs

        client = TwelveLabs(
            api_key="YOUR_API_KEY",
        )
        client.analyze_async.tasks.retrieve(
            task_id="64f8d2c7e4a1b37f8a9c5d12",
        )
        """
        _response = self._raw_client.retrieve(task_id, request_options=request_options)
        return _response.data

    def delete(self, task_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        This method deletes an analysis task. You can only delete tasks that are not currently being processed.

        Parameters
        ----------
        task_id : str
            The unique identifier of the analyze task.

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

        Returns
        -------
        None

        Examples
        --------
        from twelvelabs import TwelveLabs

        client = TwelveLabs(
            api_key="YOUR_API_KEY",
        )
        client.analyze_async.tasks.delete(
            task_id="64f8d2c7e4a1b37f8a9c5d12",
        )
        """
        _response = self._raw_client.delete(task_id, 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 list(
        self,
        *,
        page: typing.Optional[int] = None,
        page_limit: typing.Optional[int] = None,
        status: typing.Optional[AnalyzeTaskStatus] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TasksListResponse:
        """
        This method returns a list of the analysis tasks in your account. The platform returns your analysis tasks sorted by creation date, with the newest at the top of the list.

        Parameters
        ----------
        page : typing.Optional[int]
            A number that identifies the page to retrieve.

            **Default**: `1`.

        page_limit : typing.Optional[int]
            The number of items to return on each page.

            **Default**: `10`.
            **Max**: `50`.

        status : typing.Optional[AnalyzeTaskStatus]
            Filter analysis tasks by status.
            Possible values: `queued`, `pending`, `processing`, `ready`, `failed`.

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

        Returns
        -------
        TasksListResponse
            A list of analysis tasks has successfully been retrieved.

        Examples
        --------
        import asyncio

        from twelvelabs import AsyncTwelveLabs

        client = AsyncTwelveLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.analyze_async.tasks.list(
                page=1,
                page_limit=10,
                status="queued",
            )


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

    async def create(
        self,
        *,
        video: VideoContext,
        prompt: AnalyzeTextPrompt,
        temperature: typing.Optional[AnalyzeTemperature] = OMIT,
        max_tokens: typing.Optional[AnalyzeMaxTokens] = OMIT,
        response_format: typing.Optional[ResponseFormat] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateAnalyzeTaskResponse:
        """
        This method asynchronously analyzes your videos and generates fully customizable text based on your prompts.

        <Accordion title="Input requirements">
        - Minimum duration: 4 seconds
        - Maximum duration: 2 hours
        - Formats: [FFmpeg supported formats](https://ffmpeg.org/ffmpeg-formats.html)
        - Resolution: 360x360 to 5184x2160 pixels
        - Aspect ratio: Between 1:1 and 1:2.4, or between 2.4:1 and 1:1.
        </Accordion>

        **When to use this method**:
        - Analyze videos longer than 1 hour
        - Process videos asynchronously without blocking your application

        **Do not use this method for**:
        - Videos for which you need immediate results or real-time streaming. Use the [`POST`](/v1.3/api-reference/analyze-videos/sync-analysis) method of the `/analyze` endpoint instead.

        Analyzing videos asynchronously requires three steps:

        1. Create an analysis task using this method. The platform returns a task ID.
        2. Poll the status of the task using the [`GET`](/v1.3/api-reference/analyze-videos/retrieve-analysis-task-status-results) method of the `/analyze/tasks/{task_id}` endpoint. Wait until the status is `ready`.
        3. Retrieve the results from the response when the status is `ready` using the [`GET`](/v1.3/api-reference/analyze-videos/retrieve-analysis-task-status-results) method of the `/analyze/tasks/{task_id}` endpoint.

        <Note title="Note">
        This endpoint is rate-limited. For details, see the [Rate limits](/v1.3/docs/get-started/rate-limits) page.
        </Note>

        Parameters
        ----------
        video : VideoContext

        prompt : AnalyzeTextPrompt

        temperature : typing.Optional[AnalyzeTemperature]

        max_tokens : typing.Optional[AnalyzeMaxTokens]

        response_format : typing.Optional[ResponseFormat]

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

        Returns
        -------
        CreateAnalyzeTaskResponse
            An analysis task has successfully been created.

        Examples
        --------
        import asyncio

        from twelvelabs import AsyncTwelveLabs, VideoContext_Url

        client = AsyncTwelveLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.analyze_async.tasks.create(
                video=VideoContext_Url(
                    url="https://example.com/video.mp4",
                ),
                prompt="Generate a detailed summary of this video in 3-4 sentences",
                temperature=0.2,
                max_tokens=1000,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            video=video,
            prompt=prompt,
            temperature=temperature,
            max_tokens=max_tokens,
            response_format=response_format,
            request_options=request_options,
        )
        return _response.data

    async def retrieve(
        self, task_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AnalyzeTaskResponse:
        """
        This method retrieves the status and results of an analysis task.

        **Task statuses**:
        - `queued`: The task is waiting to be processed.
        - `pending`: The task is queued and waiting to start.
        - `processing`: The platform is analyzing the video.
        - `ready`: Processing is complete. Results are available in the response.
        - `failed`: The task failed. No results were generated.

        Poll this method until `status` is `ready` or `failed`. When `status` is `ready`, use the results from the response.

        Parameters
        ----------
        task_id : str
            The unique identifier of the analysis task.

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

        Returns
        -------
        AnalyzeTaskResponse
            Task status and results retrieved successfully

        Examples
        --------
        import asyncio

        from twelvelabs import AsyncTwelveLabs

        client = AsyncTwelveLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.analyze_async.tasks.retrieve(
                task_id="64f8d2c7e4a1b37f8a9c5d12",
            )


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

    async def delete(self, task_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        This method deletes an analysis task. You can only delete tasks that are not currently being processed.

        Parameters
        ----------
        task_id : str
            The unique identifier of the analyze task.

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from twelvelabs import AsyncTwelveLabs

        client = AsyncTwelveLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.analyze_async.tasks.delete(
                task_id="64f8d2c7e4a1b37f8a9c5d12",
            )


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