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

import typing

from ....core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ....core.pagination import AsyncPager, SyncPager
from ....core.request_options import RequestOptions
from ....types.audio_input_request import AudioInputRequest
from ....types.embedding_task_response import EmbeddingTaskResponse
from ....types.media_embedding_task import MediaEmbeddingTask
from ....types.video_input_request import VideoInputRequest
from .raw_client import AsyncRawTasksClient, RawTasksClient
from .types.create_async_embedding_request_input_type import CreateAsyncEmbeddingRequestInputType
from .types.create_async_embedding_request_model_name import CreateAsyncEmbeddingRequestModelName
from .types.tasks_create_response import TasksCreateResponse

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

        Parameters
        ----------
        started_at : typing.Optional[str]
            Retrieve the embedding tasks that were created after the given date and time, expressed in the RFC 3339 format ("YYYY-MM-DDTHH:mm:ssZ").

        ended_at : typing.Optional[str]
            Retrieve the embedding tasks that were created before the given date and time, expressed in the RFC 3339 format ("YYYY-MM-DDTHH:mm:ssZ").

        status : typing.Optional[str]
            Filter the embedding tasks by their current status.

            **Values**: `processing`, `ready`, or `failed`.

        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`.

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

        Returns
        -------
        SyncPager[MediaEmbeddingTask]
            A list of async embedding tasks has successfully been retrieved.

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

        client = TwelveLabs(
            api_key="YOUR_API_KEY",
        )
        response = client.embed.v_2.tasks.list(
            started_at="2024-03-01T00:00:00Z",
            ended_at="2024-03-01T00:00:00Z",
            status="processing",
            page=1,
            page_limit=10,
        )
        for item in response:
            yield item
        # alternatively, you can paginate page-by-page
        for page in response.iter_pages():
            yield page
        """
        return self._raw_client.list(
            started_at=started_at,
            ended_at=ended_at,
            status=status,
            page=page,
            page_limit=page_limit,
            request_options=request_options,
        )

    def create(
        self,
        *,
        input_type: CreateAsyncEmbeddingRequestInputType,
        model_name: CreateAsyncEmbeddingRequestModelName,
        audio: typing.Optional[AudioInputRequest] = OMIT,
        video: typing.Optional[VideoInputRequest] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TasksCreateResponse:
        """
        This endpoint creates embeddings for audio and video content asynchronously.

        **When to use this endpoint**:
        - Process audio or video files longer than 10 minutes
        - Process files up to 4 hours in duration

        <Accordion title="Input requirements">
          **Video**:
          - Minimum duration: 4 seconds
          - Maximum duration: 4 hours
          - Maximum file size: 4 GB
          - 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

          **Audio**:
          - Minimum duration: 4 seconds
          - Maximum duration: 4 hours
          - Maximum file size: 2 GB
          - Formats: WAV (uncompressed), MP3 (lossy), FLAC (lossless)
        </Accordion>

          Creating embeddings asynchronously requires three steps:

          1. Create a task using this endpoint. The platform returns a task ID.
          2. Poll for the status of the task using the [`GET`](/v1.3/api-reference/create-embeddings-v2/retrieve-embeddings) method of the `/embed-v2/tasks/{task_id}` endpoint. Wait until the status is `ready`.
          3. Retrieve the embeddings from the response when the status is `ready` using the [`GET`](/v1.3/api-reference/create-embeddings-v2/retrieve-embeddings) method of the `/embed-v2/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
        ----------
        input_type : CreateAsyncEmbeddingRequestInputType
            The type of content for the embeddings.

            **Values**:
            - `audio`: Audio files
            - `video`: Video content

        model_name : CreateAsyncEmbeddingRequestModelName
            The model you wish to use. Value: `"marengo3.0"`.

        audio : typing.Optional[AudioInputRequest]

        video : typing.Optional[VideoInputRequest]

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

        Returns
        -------
        TasksCreateResponse
            An embedding task has successfully been created.

        Examples
        --------
        from twelvelabs import (
            AudioInputRequest,
            AudioSegmentation,
            AudioSegmentationFixed,
            MediaSource,
            TwelveLabs,
        )

        client = TwelveLabs(
            api_key="YOUR_API_KEY",
        )
        client.embed.v_2.tasks.create(
            input_type="audio",
            model_name="marengo3.0",
            audio=AudioInputRequest(
                media_source=MediaSource(
                    url="https://user-bucket.com/audio/long-audio.wav",
                ),
                start_sec=0.0,
                end_sec=3600.0,
                segmentation=AudioSegmentation(
                    strategy="fixed",
                    fixed=AudioSegmentationFixed(
                        duration_sec=6,
                    ),
                ),
                embedding_option=["audio", "transcription"],
                embedding_scope=["clip", "asset"],
            ),
        )
        """
        _response = self._raw_client.create(
            input_type=input_type, model_name=model_name, audio=audio, video=video, request_options=request_options
        )
        return _response.data

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

        **Task statuses**:
        - `processing`: The platform is creating the embeddings.
        - `ready`: Processing is complete. Embeddings are available in the response.
        - `failed`: The task failed. Embeddings were not created.

        Invoke this method repeatedly until the `status` field is `ready`. When `status` is `ready`, use the embeddings from the response.

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

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

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

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

        client = TwelveLabs(
            api_key="YOUR_API_KEY",
        )
        client.embed.v_2.tasks.retrieve(
            task_id="64f8d2c7e4a1b37f8a9c5d12",
        )
        """
        _response = self._raw_client.retrieve(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,
        *,
        started_at: typing.Optional[str] = None,
        ended_at: typing.Optional[str] = None,
        status: typing.Optional[str] = None,
        page: typing.Optional[int] = None,
        page_limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[MediaEmbeddingTask]:
        """
        This method returns a list of the async embedding tasks in your account. The platform returns your async embedding tasks sorted by creation date, with the newest at the top of the list.

        Parameters
        ----------
        started_at : typing.Optional[str]
            Retrieve the embedding tasks that were created after the given date and time, expressed in the RFC 3339 format ("YYYY-MM-DDTHH:mm:ssZ").

        ended_at : typing.Optional[str]
            Retrieve the embedding tasks that were created before the given date and time, expressed in the RFC 3339 format ("YYYY-MM-DDTHH:mm:ssZ").

        status : typing.Optional[str]
            Filter the embedding tasks by their current status.

            **Values**: `processing`, `ready`, or `failed`.

        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`.

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

        Returns
        -------
        AsyncPager[MediaEmbeddingTask]
            A list of async embedding tasks has successfully been retrieved.

        Examples
        --------
        import asyncio

        from twelvelabs import AsyncTwelveLabs

        client = AsyncTwelveLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            response = await client.embed.v_2.tasks.list(
                started_at="2024-03-01T00:00:00Z",
                ended_at="2024-03-01T00:00:00Z",
                status="processing",
                page=1,
                page_limit=10,
            )
            async for item in response:
                yield item

            # alternatively, you can paginate page-by-page
            async for page in response.iter_pages():
                yield page


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

    async def create(
        self,
        *,
        input_type: CreateAsyncEmbeddingRequestInputType,
        model_name: CreateAsyncEmbeddingRequestModelName,
        audio: typing.Optional[AudioInputRequest] = OMIT,
        video: typing.Optional[VideoInputRequest] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TasksCreateResponse:
        """
        This endpoint creates embeddings for audio and video content asynchronously.

        **When to use this endpoint**:
        - Process audio or video files longer than 10 minutes
        - Process files up to 4 hours in duration

        <Accordion title="Input requirements">
          **Video**:
          - Minimum duration: 4 seconds
          - Maximum duration: 4 hours
          - Maximum file size: 4 GB
          - 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

          **Audio**:
          - Minimum duration: 4 seconds
          - Maximum duration: 4 hours
          - Maximum file size: 2 GB
          - Formats: WAV (uncompressed), MP3 (lossy), FLAC (lossless)
        </Accordion>

          Creating embeddings asynchronously requires three steps:

          1. Create a task using this endpoint. The platform returns a task ID.
          2. Poll for the status of the task using the [`GET`](/v1.3/api-reference/create-embeddings-v2/retrieve-embeddings) method of the `/embed-v2/tasks/{task_id}` endpoint. Wait until the status is `ready`.
          3. Retrieve the embeddings from the response when the status is `ready` using the [`GET`](/v1.3/api-reference/create-embeddings-v2/retrieve-embeddings) method of the `/embed-v2/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
        ----------
        input_type : CreateAsyncEmbeddingRequestInputType
            The type of content for the embeddings.

            **Values**:
            - `audio`: Audio files
            - `video`: Video content

        model_name : CreateAsyncEmbeddingRequestModelName
            The model you wish to use. Value: `"marengo3.0"`.

        audio : typing.Optional[AudioInputRequest]

        video : typing.Optional[VideoInputRequest]

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

        Returns
        -------
        TasksCreateResponse
            An embedding task has successfully been created.

        Examples
        --------
        import asyncio

        from twelvelabs import (
            AsyncTwelveLabs,
            AudioInputRequest,
            AudioSegmentation,
            AudioSegmentationFixed,
            MediaSource,
        )

        client = AsyncTwelveLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.embed.v_2.tasks.create(
                input_type="audio",
                model_name="marengo3.0",
                audio=AudioInputRequest(
                    media_source=MediaSource(
                        url="https://user-bucket.com/audio/long-audio.wav",
                    ),
                    start_sec=0.0,
                    end_sec=3600.0,
                    segmentation=AudioSegmentation(
                        strategy="fixed",
                        fixed=AudioSegmentationFixed(
                            duration_sec=6,
                        ),
                    ),
                    embedding_option=["audio", "transcription"],
                    embedding_scope=["clip", "asset"],
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            input_type=input_type, model_name=model_name, audio=audio, video=video, request_options=request_options
        )
        return _response.data

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

        **Task statuses**:
        - `processing`: The platform is creating the embeddings.
        - `ready`: Processing is complete. Embeddings are available in the response.
        - `failed`: The task failed. Embeddings were not created.

        Invoke this method repeatedly until the `status` field is `ready`. When `status` is `ready`, use the embeddings from the response.

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

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

        Returns
        -------
        EmbeddingTaskResponse
            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.embed.v_2.tasks.retrieve(
                task_id="64f8d2c7e4a1b37f8a9c5d12",
            )


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