# 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 (
    AsyncRawBlobStorageIntegrationsClient,
    RawBlobStorageIntegrationsClient,
)
from .types.blob_storage_export_frequency import BlobStorageExportFrequency
from .types.blob_storage_export_mode import BlobStorageExportMode
from .types.blob_storage_integration_deletion_response import (
    BlobStorageIntegrationDeletionResponse,
)
from .types.blob_storage_integration_file_type import BlobStorageIntegrationFileType
from .types.blob_storage_integration_response import BlobStorageIntegrationResponse
from .types.blob_storage_integration_type import BlobStorageIntegrationType
from .types.blob_storage_integrations_response import BlobStorageIntegrationsResponse

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


class BlobStorageIntegrationsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawBlobStorageIntegrationsClient(
            client_wrapper=client_wrapper
        )

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

        Returns
        -------
        RawBlobStorageIntegrationsClient
        """
        return self._raw_client

    def get_blob_storage_integrations(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> BlobStorageIntegrationsResponse:
        """
        Get all blob storage integrations for the organization (requires organization-scoped API key)

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

        Returns
        -------
        BlobStorageIntegrationsResponse

        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.blob_storage_integrations.get_blob_storage_integrations()
        """
        _response = self._raw_client.get_blob_storage_integrations(
            request_options=request_options
        )
        return _response.data

    def upsert_blob_storage_integration(
        self,
        *,
        project_id: str,
        type: BlobStorageIntegrationType,
        bucket_name: str,
        region: str,
        export_frequency: BlobStorageExportFrequency,
        enabled: bool,
        force_path_style: bool,
        file_type: BlobStorageIntegrationFileType,
        export_mode: BlobStorageExportMode,
        endpoint: typing.Optional[str] = OMIT,
        access_key_id: typing.Optional[str] = OMIT,
        secret_access_key: typing.Optional[str] = OMIT,
        prefix: typing.Optional[str] = OMIT,
        export_start_date: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> BlobStorageIntegrationResponse:
        """
        Create or update a blob storage integration for a specific project (requires organization-scoped API key). The configuration is validated by performing a test upload to the bucket.

        Parameters
        ----------
        project_id : str
            ID of the project in which to configure the blob storage integration

        type : BlobStorageIntegrationType

        bucket_name : str
            Name of the storage bucket

        region : str
            Storage region

        export_frequency : BlobStorageExportFrequency

        enabled : bool
            Whether the integration is active

        force_path_style : bool
            Use path-style URLs for S3 requests

        file_type : BlobStorageIntegrationFileType

        export_mode : BlobStorageExportMode

        endpoint : typing.Optional[str]
            Custom endpoint URL (required for S3_COMPATIBLE type)

        access_key_id : typing.Optional[str]
            Access key ID for authentication

        secret_access_key : typing.Optional[str]
            Secret access key for authentication (will be encrypted when stored)

        prefix : typing.Optional[str]
            Path prefix for exported files (must end with forward slash if provided)

        export_start_date : typing.Optional[dt.datetime]
            Custom start date for exports (required when exportMode is FROM_CUSTOM_DATE)

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

        Returns
        -------
        BlobStorageIntegrationResponse

        Examples
        --------
        from langfuse import LangfuseAPI
        from langfuse.blob_storage_integrations import (
            BlobStorageExportFrequency,
            BlobStorageExportMode,
            BlobStorageIntegrationFileType,
            BlobStorageIntegrationType,
        )

        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.blob_storage_integrations.upsert_blob_storage_integration(
            project_id="projectId",
            type=BlobStorageIntegrationType.S3,
            bucket_name="bucketName",
            region="region",
            export_frequency=BlobStorageExportFrequency.HOURLY,
            enabled=True,
            force_path_style=True,
            file_type=BlobStorageIntegrationFileType.JSON,
            export_mode=BlobStorageExportMode.FULL_HISTORY,
        )
        """
        _response = self._raw_client.upsert_blob_storage_integration(
            project_id=project_id,
            type=type,
            bucket_name=bucket_name,
            region=region,
            export_frequency=export_frequency,
            enabled=enabled,
            force_path_style=force_path_style,
            file_type=file_type,
            export_mode=export_mode,
            endpoint=endpoint,
            access_key_id=access_key_id,
            secret_access_key=secret_access_key,
            prefix=prefix,
            export_start_date=export_start_date,
            request_options=request_options,
        )
        return _response.data

    def delete_blob_storage_integration(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> BlobStorageIntegrationDeletionResponse:
        """
        Delete a blob storage integration by ID (requires organization-scoped API key)

        Parameters
        ----------
        id : str

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

        Returns
        -------
        BlobStorageIntegrationDeletionResponse

        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.blob_storage_integrations.delete_blob_storage_integration(
            id="id",
        )
        """
        _response = self._raw_client.delete_blob_storage_integration(
            id, request_options=request_options
        )
        return _response.data


class AsyncBlobStorageIntegrationsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawBlobStorageIntegrationsClient(
            client_wrapper=client_wrapper
        )

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

        Returns
        -------
        AsyncRawBlobStorageIntegrationsClient
        """
        return self._raw_client

    async def get_blob_storage_integrations(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> BlobStorageIntegrationsResponse:
        """
        Get all blob storage integrations for the organization (requires organization-scoped API key)

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

        Returns
        -------
        BlobStorageIntegrationsResponse

        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.blob_storage_integrations.get_blob_storage_integrations()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_blob_storage_integrations(
            request_options=request_options
        )
        return _response.data

    async def upsert_blob_storage_integration(
        self,
        *,
        project_id: str,
        type: BlobStorageIntegrationType,
        bucket_name: str,
        region: str,
        export_frequency: BlobStorageExportFrequency,
        enabled: bool,
        force_path_style: bool,
        file_type: BlobStorageIntegrationFileType,
        export_mode: BlobStorageExportMode,
        endpoint: typing.Optional[str] = OMIT,
        access_key_id: typing.Optional[str] = OMIT,
        secret_access_key: typing.Optional[str] = OMIT,
        prefix: typing.Optional[str] = OMIT,
        export_start_date: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> BlobStorageIntegrationResponse:
        """
        Create or update a blob storage integration for a specific project (requires organization-scoped API key). The configuration is validated by performing a test upload to the bucket.

        Parameters
        ----------
        project_id : str
            ID of the project in which to configure the blob storage integration

        type : BlobStorageIntegrationType

        bucket_name : str
            Name of the storage bucket

        region : str
            Storage region

        export_frequency : BlobStorageExportFrequency

        enabled : bool
            Whether the integration is active

        force_path_style : bool
            Use path-style URLs for S3 requests

        file_type : BlobStorageIntegrationFileType

        export_mode : BlobStorageExportMode

        endpoint : typing.Optional[str]
            Custom endpoint URL (required for S3_COMPATIBLE type)

        access_key_id : typing.Optional[str]
            Access key ID for authentication

        secret_access_key : typing.Optional[str]
            Secret access key for authentication (will be encrypted when stored)

        prefix : typing.Optional[str]
            Path prefix for exported files (must end with forward slash if provided)

        export_start_date : typing.Optional[dt.datetime]
            Custom start date for exports (required when exportMode is FROM_CUSTOM_DATE)

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

        Returns
        -------
        BlobStorageIntegrationResponse

        Examples
        --------
        import asyncio

        from langfuse import AsyncLangfuseAPI
        from langfuse.blob_storage_integrations import (
            BlobStorageExportFrequency,
            BlobStorageExportMode,
            BlobStorageIntegrationFileType,
            BlobStorageIntegrationType,
        )

        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.blob_storage_integrations.upsert_blob_storage_integration(
                project_id="projectId",
                type=BlobStorageIntegrationType.S3,
                bucket_name="bucketName",
                region="region",
                export_frequency=BlobStorageExportFrequency.HOURLY,
                enabled=True,
                force_path_style=True,
                file_type=BlobStorageIntegrationFileType.JSON,
                export_mode=BlobStorageExportMode.FULL_HISTORY,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.upsert_blob_storage_integration(
            project_id=project_id,
            type=type,
            bucket_name=bucket_name,
            region=region,
            export_frequency=export_frequency,
            enabled=enabled,
            force_path_style=force_path_style,
            file_type=file_type,
            export_mode=export_mode,
            endpoint=endpoint,
            access_key_id=access_key_id,
            secret_access_key=secret_access_key,
            prefix=prefix,
            export_start_date=export_start_date,
            request_options=request_options,
        )
        return _response.data

    async def delete_blob_storage_integration(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> BlobStorageIntegrationDeletionResponse:
        """
        Delete a blob storage integration by ID (requires organization-scoped API key)

        Parameters
        ----------
        id : str

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

        Returns
        -------
        BlobStorageIntegrationDeletionResponse

        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.blob_storage_integrations.delete_blob_storage_integration(
                id="id",
            )


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