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

import typing

from .. import core
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.pagination import AsyncPager, SyncPager
from ..core.request_options import RequestOptions
from ..types.asset import Asset
from .raw_client import AsyncRawAssetsClient, RawAssetsClient
from .types.assets_create_request_method import AssetsCreateRequestMethod
from .types.assets_list_request_asset_types_item import AssetsListRequestAssetTypesItem

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


class AssetsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawAssetsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawAssetsClient
        """
        return self._raw_client

    def list(
        self,
        *,
        page: typing.Optional[int] = None,
        page_limit: typing.Optional[int] = None,
        asset_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        asset_types: typing.Optional[
            typing.Union[AssetsListRequestAssetTypesItem, typing.Sequence[AssetsListRequestAssetTypesItem]]
        ] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[Asset]:
        """
        This method returns a list of assets in your account.

        The platform returns your assets 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`.

        asset_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Filters the response to include only assets with the specified IDs. Provide one or more asset IDs. When you specify multiple IDs, the platform returns all matching assets.

        asset_types : typing.Optional[typing.Union[AssetsListRequestAssetTypesItem, typing.Sequence[AssetsListRequestAssetTypesItem]]]
            Filters the response to include only assets of the specified types. Provide one or more asset types. When you specify multiple types, the platform returns all matching assets.

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

        Returns
        -------
        SyncPager[Asset]
            The assets have been successfully retrieved.

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

        client = TwelveLabs(
            api_key="YOUR_API_KEY",
        )
        response = client.assets.list(
            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(
            page=page,
            page_limit=page_limit,
            asset_ids=asset_ids,
            asset_types=asset_types,
            request_options=request_options,
        )

    def create(
        self,
        *,
        method: AssetsCreateRequestMethod,
        file: typing.Optional[core.File] = OMIT,
        url: typing.Optional[str] = OMIT,
        filename: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Asset:
        """
        This method creates an asset by uploading a file to the platform. Assets are media files that you can use in downstream workflows, including indexing, analyzing video content, and creating entities.

        **Supported content**: Video, audio, and images.

        **Upload methods**:
        - **Local file**: Set the `method` parameter to `direct` and use the `file` parameter to specify the file.
        - **Publicly accessible URL**: Set the `method` parameter to `url` and use the `url` parameter to specify the URL of your file.

        **File size**: 200MB maximum for local file uploads, 4GB maximum for URL uploads.

        **Additional requirements** depend on your workflow:
        - **Search**: [Marengo requirements](/v1.3/docs/concepts/models/marengo#video-file-requirements)
        - **Video analysis**: [Pegasus requirements](/v1.3/docs/concepts/models/pegasus#input-requirements)
        - **Entity search**: [Marengo image requirements](/v1.3/docs/concepts/models/marengo#image-file-requirements)
        - **Create embeddings**: [Marengo requirements](/v1.3/docs/concepts/models/marengo#input-requirements)

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

        Parameters
        ----------
        method : AssetsCreateRequestMethod
            Specifies the upload method for the asset. Use `direct` to upload a local file or `url` for a publicly accessible URL.

        file : typing.Optional[core.File]
            See core.File for more documentation

        url : typing.Optional[str]
            Specify this parameter to upload a file from a publicly accessible URL. This parameter is required when `method` is set to `url`.

            URL uploads have a maximum limit of 4GB.

        filename : typing.Optional[str]
            The optional filename of the asset. If not provided, the platform will determine the filename from the file or URL.

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

        Returns
        -------
        Asset
            The asset has been successfully created.

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

        client = TwelveLabs(
            api_key="YOUR_API_KEY",
        )
        client.assets.create(
            method="direct",
        )
        """
        _response = self._raw_client.create(
            method=method, file=file, url=url, filename=filename, request_options=request_options
        )
        return _response.data

    def retrieve(self, asset_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> Asset:
        """
        This method retrieves details about the specified asset.

        Parameters
        ----------
        asset_id : str
            The unique identifier of the asset to retrieve.

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

        Returns
        -------
        Asset
            The asset has been successfully retrieved.

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

        client = TwelveLabs(
            api_key="YOUR_API_KEY",
        )
        client.assets.retrieve(
            asset_id="6298d673f1090f1100476d4c",
        )
        """
        _response = self._raw_client.retrieve(asset_id, request_options=request_options)
        return _response.data

    def delete(self, asset_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        This method deletes the specified asset. This action cannot be undone.

        Parameters
        ----------
        asset_id : str
            The unique identifier of the asset to delete.

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

        Returns
        -------
        None

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

        client = TwelveLabs(
            api_key="YOUR_API_KEY",
        )
        client.assets.delete(
            asset_id="6298d673f1090f1100476d4c",
        )
        """
        _response = self._raw_client.delete(asset_id, request_options=request_options)
        return _response.data


class AsyncAssetsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawAssetsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawAssetsClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        page: typing.Optional[int] = None,
        page_limit: typing.Optional[int] = None,
        asset_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        asset_types: typing.Optional[
            typing.Union[AssetsListRequestAssetTypesItem, typing.Sequence[AssetsListRequestAssetTypesItem]]
        ] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[Asset]:
        """
        This method returns a list of assets in your account.

        The platform returns your assets 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`.

        asset_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Filters the response to include only assets with the specified IDs. Provide one or more asset IDs. When you specify multiple IDs, the platform returns all matching assets.

        asset_types : typing.Optional[typing.Union[AssetsListRequestAssetTypesItem, typing.Sequence[AssetsListRequestAssetTypesItem]]]
            Filters the response to include only assets of the specified types. Provide one or more asset types. When you specify multiple types, the platform returns all matching assets.

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

        Returns
        -------
        AsyncPager[Asset]
            The assets have been successfully retrieved.

        Examples
        --------
        import asyncio

        from twelvelabs import AsyncTwelveLabs

        client = AsyncTwelveLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            response = await client.assets.list(
                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(
            page=page,
            page_limit=page_limit,
            asset_ids=asset_ids,
            asset_types=asset_types,
            request_options=request_options,
        )

    async def create(
        self,
        *,
        method: AssetsCreateRequestMethod,
        file: typing.Optional[core.File] = OMIT,
        url: typing.Optional[str] = OMIT,
        filename: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Asset:
        """
        This method creates an asset by uploading a file to the platform. Assets are media files that you can use in downstream workflows, including indexing, analyzing video content, and creating entities.

        **Supported content**: Video, audio, and images.

        **Upload methods**:
        - **Local file**: Set the `method` parameter to `direct` and use the `file` parameter to specify the file.
        - **Publicly accessible URL**: Set the `method` parameter to `url` and use the `url` parameter to specify the URL of your file.

        **File size**: 200MB maximum for local file uploads, 4GB maximum for URL uploads.

        **Additional requirements** depend on your workflow:
        - **Search**: [Marengo requirements](/v1.3/docs/concepts/models/marengo#video-file-requirements)
        - **Video analysis**: [Pegasus requirements](/v1.3/docs/concepts/models/pegasus#input-requirements)
        - **Entity search**: [Marengo image requirements](/v1.3/docs/concepts/models/marengo#image-file-requirements)
        - **Create embeddings**: [Marengo requirements](/v1.3/docs/concepts/models/marengo#input-requirements)

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

        Parameters
        ----------
        method : AssetsCreateRequestMethod
            Specifies the upload method for the asset. Use `direct` to upload a local file or `url` for a publicly accessible URL.

        file : typing.Optional[core.File]
            See core.File for more documentation

        url : typing.Optional[str]
            Specify this parameter to upload a file from a publicly accessible URL. This parameter is required when `method` is set to `url`.

            URL uploads have a maximum limit of 4GB.

        filename : typing.Optional[str]
            The optional filename of the asset. If not provided, the platform will determine the filename from the file or URL.

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

        Returns
        -------
        Asset
            The asset has been successfully created.

        Examples
        --------
        import asyncio

        from twelvelabs import AsyncTwelveLabs

        client = AsyncTwelveLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.assets.create(
                method="direct",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            method=method, file=file, url=url, filename=filename, request_options=request_options
        )
        return _response.data

    async def retrieve(self, asset_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> Asset:
        """
        This method retrieves details about the specified asset.

        Parameters
        ----------
        asset_id : str
            The unique identifier of the asset to retrieve.

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

        Returns
        -------
        Asset
            The asset has been successfully retrieved.

        Examples
        --------
        import asyncio

        from twelvelabs import AsyncTwelveLabs

        client = AsyncTwelveLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.assets.retrieve(
                asset_id="6298d673f1090f1100476d4c",
            )


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

    async def delete(self, asset_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        This method deletes the specified asset. This action cannot be undone.

        Parameters
        ----------
        asset_id : str
            The unique identifier of the asset to delete.

        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.assets.delete(
                asset_id="6298d673f1090f1100476d4c",
            )


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