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

import datetime as dt
import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from .raw_client import AsyncRawMediaClient, RawMediaClient
from .types.get_media_response import GetMediaResponse
from .types.get_media_upload_url_response import GetMediaUploadUrlResponse
from .types.media_content_type import MediaContentType

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


class MediaClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawMediaClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawMediaClient
        """
        return self._raw_client

    def get(
        self, media_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetMediaResponse:
        """
        Get a media record

        Parameters
        ----------
        media_id : str
            The unique langfuse identifier of a media record

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

        Returns
        -------
        GetMediaResponse

        Examples
        --------
        from langfuse import LangfuseAPI

        client = LangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )
        client.media.get(
            media_id="mediaId",
        )
        """
        _response = self._raw_client.get(media_id, request_options=request_options)
        return _response.data

    def patch(
        self,
        media_id: str,
        *,
        uploaded_at: dt.datetime,
        upload_http_status: int,
        upload_http_error: typing.Optional[str] = OMIT,
        upload_time_ms: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Patch a media record

        Parameters
        ----------
        media_id : str
            The unique langfuse identifier of a media record

        uploaded_at : dt.datetime
            The date and time when the media record was uploaded

        upload_http_status : int
            The HTTP status code of the upload

        upload_http_error : typing.Optional[str]
            The HTTP error message of the upload

        upload_time_ms : typing.Optional[int]
            The time in milliseconds it took to upload the media record

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

        Returns
        -------
        None

        Examples
        --------
        import datetime

        from langfuse import LangfuseAPI

        client = LangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )
        client.media.patch(
            media_id="mediaId",
            uploaded_at=datetime.datetime.fromisoformat(
                "2024-01-15 09:30:00+00:00",
            ),
            upload_http_status=1,
        )
        """
        _response = self._raw_client.patch(
            media_id,
            uploaded_at=uploaded_at,
            upload_http_status=upload_http_status,
            upload_http_error=upload_http_error,
            upload_time_ms=upload_time_ms,
            request_options=request_options,
        )
        return _response.data

    def get_upload_url(
        self,
        *,
        trace_id: str,
        content_type: MediaContentType,
        content_length: int,
        sha256hash: str,
        field: str,
        observation_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetMediaUploadUrlResponse:
        """
        Get a presigned upload URL for a media record

        Parameters
        ----------
        trace_id : str
            The trace ID associated with the media record

        content_type : MediaContentType

        content_length : int
            The size of the media record in bytes

        sha256hash : str
            The SHA-256 hash of the media record

        field : str
            The trace / observation field the media record is associated with. This can be one of `input`, `output`, `metadata`

        observation_id : typing.Optional[str]
            The observation ID associated with the media record. If the media record is associated directly with a trace, this will be null.

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

        Returns
        -------
        GetMediaUploadUrlResponse

        Examples
        --------
        from langfuse import LangfuseAPI
        from langfuse.media import MediaContentType

        client = LangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )
        client.media.get_upload_url(
            trace_id="traceId",
            content_type=MediaContentType.IMAGE_PNG,
            content_length=1,
            sha256hash="sha256Hash",
            field="field",
        )
        """
        _response = self._raw_client.get_upload_url(
            trace_id=trace_id,
            content_type=content_type,
            content_length=content_length,
            sha256hash=sha256hash,
            field=field,
            observation_id=observation_id,
            request_options=request_options,
        )
        return _response.data


class AsyncMediaClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawMediaClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawMediaClient
        """
        return self._raw_client

    async def get(
        self, media_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetMediaResponse:
        """
        Get a media record

        Parameters
        ----------
        media_id : str
            The unique langfuse identifier of a media record

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

        Returns
        -------
        GetMediaResponse

        Examples
        --------
        import asyncio

        from langfuse import AsyncLangfuseAPI

        client = AsyncLangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.media.get(
                media_id="mediaId",
            )


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

    async def patch(
        self,
        media_id: str,
        *,
        uploaded_at: dt.datetime,
        upload_http_status: int,
        upload_http_error: typing.Optional[str] = OMIT,
        upload_time_ms: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Patch a media record

        Parameters
        ----------
        media_id : str
            The unique langfuse identifier of a media record

        uploaded_at : dt.datetime
            The date and time when the media record was uploaded

        upload_http_status : int
            The HTTP status code of the upload

        upload_http_error : typing.Optional[str]
            The HTTP error message of the upload

        upload_time_ms : typing.Optional[int]
            The time in milliseconds it took to upload the media record

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio
        import datetime

        from langfuse import AsyncLangfuseAPI

        client = AsyncLangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.media.patch(
                media_id="mediaId",
                uploaded_at=datetime.datetime.fromisoformat(
                    "2024-01-15 09:30:00+00:00",
                ),
                upload_http_status=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.patch(
            media_id,
            uploaded_at=uploaded_at,
            upload_http_status=upload_http_status,
            upload_http_error=upload_http_error,
            upload_time_ms=upload_time_ms,
            request_options=request_options,
        )
        return _response.data

    async def get_upload_url(
        self,
        *,
        trace_id: str,
        content_type: MediaContentType,
        content_length: int,
        sha256hash: str,
        field: str,
        observation_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetMediaUploadUrlResponse:
        """
        Get a presigned upload URL for a media record

        Parameters
        ----------
        trace_id : str
            The trace ID associated with the media record

        content_type : MediaContentType

        content_length : int
            The size of the media record in bytes

        sha256hash : str
            The SHA-256 hash of the media record

        field : str
            The trace / observation field the media record is associated with. This can be one of `input`, `output`, `metadata`

        observation_id : typing.Optional[str]
            The observation ID associated with the media record. If the media record is associated directly with a trace, this will be null.

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

        Returns
        -------
        GetMediaUploadUrlResponse

        Examples
        --------
        import asyncio

        from langfuse import AsyncLangfuseAPI
        from langfuse.media import MediaContentType

        client = AsyncLangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.media.get_upload_url(
                trace_id="traceId",
                content_type=MediaContentType.IMAGE_PNG,
                content_length=1,
                sha256hash="sha256Hash",
                field="field",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_upload_url(
            trace_id=trace_id,
            content_type=content_type,
            content_length=content_length,
            sha256hash=sha256hash,
            field=field,
            observation_id=observation_id,
            request_options=request_options,
        )
        return _response.data
