# 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.dashboard_page_public import DashboardPagePublic
from ..types.dashboard_public import DashboardPublic
from ..types.dashboard_update_public_type import DashboardUpdatePublicType
from ..types.dashboard_write_type import DashboardWriteType
from ..types.json_node_public import JsonNodePublic
from ..types.json_node_write import JsonNodeWrite
from .raw_client import AsyncRawInsightsViewsClient, RawInsightsViewsClient

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


class InsightsViewsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawInsightsViewsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawInsightsViewsClient
        """
        return self._raw_client

    def find_insights_views(
        self,
        *,
        page: typing.Optional[int] = None,
        size: typing.Optional[int] = None,
        name: typing.Optional[str] = None,
        project_id: typing.Optional[str] = None,
        sorting: typing.Optional[str] = None,
        filters: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DashboardPagePublic:
        """
        Find insights views in a workspace

        Parameters
        ----------
        page : typing.Optional[int]

        size : typing.Optional[int]

        name : typing.Optional[str]

        project_id : typing.Optional[str]

        sorting : typing.Optional[str]

        filters : typing.Optional[str]

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

        Returns
        -------
        DashboardPagePublic
            Insights view page

        Examples
        --------
        from Opik import OpikApi
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.insights_views.find_insights_views()
        """
        _response = self._raw_client.find_insights_views(
            page=page,
            size=size,
            name=name,
            project_id=project_id,
            sorting=sorting,
            filters=filters,
            request_options=request_options,
        )
        return _response.data

    def create_insights_view(
        self,
        *,
        name: str,
        config: JsonNodeWrite,
        project_id: typing.Optional[str] = OMIT,
        project_name: typing.Optional[str] = OMIT,
        type: typing.Optional[DashboardWriteType] = OMIT,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DashboardPublic:
        """
        Create a new insights view in a workspace

        Parameters
        ----------
        name : str

        config : JsonNodeWrite

        project_id : typing.Optional[str]
            Project ID. Takes precedence over project_name when both are provided.

        project_name : typing.Optional[str]
            For project scope, specify either project_id or project_name. If project_name is provided and the project does not exist, it will be created. Ignored when project_id is provided. If neither is provided, the dashboard is created at workspace level.

        type : typing.Optional[DashboardWriteType]

        description : typing.Optional[str]

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

        Returns
        -------
        DashboardPublic
            Created

        Examples
        --------
        from Opik import OpikApi
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.insights_views.create_insights_view(name='name', config={'key': 'value'
        }, )
        """
        _response = self._raw_client.create_insights_view(
            name=name,
            config=config,
            project_id=project_id,
            project_name=project_name,
            type=type,
            description=description,
            request_options=request_options,
        )
        return _response.data

    def get_insights_view_by_id(
        self, insights_view_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DashboardPublic:
        """
        Get insights view by id

        Parameters
        ----------
        insights_view_id : str

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

        Returns
        -------
        DashboardPublic
            Insights view resource

        Examples
        --------
        from Opik import OpikApi
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.insights_views.get_insights_view_by_id(insights_view_id='insightsViewId', )
        """
        _response = self._raw_client.get_insights_view_by_id(insights_view_id, request_options=request_options)
        return _response.data

    def delete_insights_view(
        self, insights_view_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete insights view by id

        Parameters
        ----------
        insights_view_id : str

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

        Returns
        -------
        None

        Examples
        --------
        from Opik import OpikApi
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.insights_views.delete_insights_view(insights_view_id='insightsViewId', )
        """
        _response = self._raw_client.delete_insights_view(insights_view_id, request_options=request_options)
        return _response.data

    def update_insights_view(
        self,
        insights_view_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        type: typing.Optional[DashboardUpdatePublicType] = OMIT,
        description: typing.Optional[str] = OMIT,
        config: typing.Optional[JsonNodePublic] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DashboardPublic:
        """
        Update insights view by id. Partial updates are supported - only provided fields will be updated.

        Parameters
        ----------
        insights_view_id : str

        name : typing.Optional[str]

        type : typing.Optional[DashboardUpdatePublicType]

        description : typing.Optional[str]

        config : typing.Optional[JsonNodePublic]

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

        Returns
        -------
        DashboardPublic
            Updated insights view

        Examples
        --------
        from Opik import OpikApi
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.insights_views.update_insights_view(insights_view_id='insightsViewId', )
        """
        _response = self._raw_client.update_insights_view(
            insights_view_id,
            name=name,
            type=type,
            description=description,
            config=config,
            request_options=request_options,
        )
        return _response.data

    def delete_insights_views_batch(
        self, *, ids: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete insights views batch

        Parameters
        ----------
        ids : typing.Sequence[str]

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

        Returns
        -------
        None

        Examples
        --------
        from Opik import OpikApi
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.insights_views.delete_insights_views_batch(ids=['ids'], )
        """
        _response = self._raw_client.delete_insights_views_batch(ids=ids, request_options=request_options)
        return _response.data


class AsyncInsightsViewsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawInsightsViewsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawInsightsViewsClient
        """
        return self._raw_client

    async def find_insights_views(
        self,
        *,
        page: typing.Optional[int] = None,
        size: typing.Optional[int] = None,
        name: typing.Optional[str] = None,
        project_id: typing.Optional[str] = None,
        sorting: typing.Optional[str] = None,
        filters: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DashboardPagePublic:
        """
        Find insights views in a workspace

        Parameters
        ----------
        page : typing.Optional[int]

        size : typing.Optional[int]

        name : typing.Optional[str]

        project_id : typing.Optional[str]

        sorting : typing.Optional[str]

        filters : typing.Optional[str]

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

        Returns
        -------
        DashboardPagePublic
            Insights view page

        Examples
        --------
        from Opik import AsyncOpikApi
        import asyncio
        client = AsyncOpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        async def main() -> None:
            await client.insights_views.find_insights_views()
        asyncio.run(main())
        """
        _response = await self._raw_client.find_insights_views(
            page=page,
            size=size,
            name=name,
            project_id=project_id,
            sorting=sorting,
            filters=filters,
            request_options=request_options,
        )
        return _response.data

    async def create_insights_view(
        self,
        *,
        name: str,
        config: JsonNodeWrite,
        project_id: typing.Optional[str] = OMIT,
        project_name: typing.Optional[str] = OMIT,
        type: typing.Optional[DashboardWriteType] = OMIT,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DashboardPublic:
        """
        Create a new insights view in a workspace

        Parameters
        ----------
        name : str

        config : JsonNodeWrite

        project_id : typing.Optional[str]
            Project ID. Takes precedence over project_name when both are provided.

        project_name : typing.Optional[str]
            For project scope, specify either project_id or project_name. If project_name is provided and the project does not exist, it will be created. Ignored when project_id is provided. If neither is provided, the dashboard is created at workspace level.

        type : typing.Optional[DashboardWriteType]

        description : typing.Optional[str]

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

        Returns
        -------
        DashboardPublic
            Created

        Examples
        --------
        from Opik import AsyncOpikApi
        import asyncio
        client = AsyncOpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        async def main() -> None:
            await client.insights_views.create_insights_view(name='name', config={'key': 'value'
            }, )
        asyncio.run(main())
        """
        _response = await self._raw_client.create_insights_view(
            name=name,
            config=config,
            project_id=project_id,
            project_name=project_name,
            type=type,
            description=description,
            request_options=request_options,
        )
        return _response.data

    async def get_insights_view_by_id(
        self, insights_view_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DashboardPublic:
        """
        Get insights view by id

        Parameters
        ----------
        insights_view_id : str

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

        Returns
        -------
        DashboardPublic
            Insights view resource

        Examples
        --------
        from Opik import AsyncOpikApi
        import asyncio
        client = AsyncOpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        async def main() -> None:
            await client.insights_views.get_insights_view_by_id(insights_view_id='insightsViewId', )
        asyncio.run(main())
        """
        _response = await self._raw_client.get_insights_view_by_id(insights_view_id, request_options=request_options)
        return _response.data

    async def delete_insights_view(
        self, insights_view_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete insights view by id

        Parameters
        ----------
        insights_view_id : str

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

        Returns
        -------
        None

        Examples
        --------
        from Opik import AsyncOpikApi
        import asyncio
        client = AsyncOpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        async def main() -> None:
            await client.insights_views.delete_insights_view(insights_view_id='insightsViewId', )
        asyncio.run(main())
        """
        _response = await self._raw_client.delete_insights_view(insights_view_id, request_options=request_options)
        return _response.data

    async def update_insights_view(
        self,
        insights_view_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        type: typing.Optional[DashboardUpdatePublicType] = OMIT,
        description: typing.Optional[str] = OMIT,
        config: typing.Optional[JsonNodePublic] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DashboardPublic:
        """
        Update insights view by id. Partial updates are supported - only provided fields will be updated.

        Parameters
        ----------
        insights_view_id : str

        name : typing.Optional[str]

        type : typing.Optional[DashboardUpdatePublicType]

        description : typing.Optional[str]

        config : typing.Optional[JsonNodePublic]

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

        Returns
        -------
        DashboardPublic
            Updated insights view

        Examples
        --------
        from Opik import AsyncOpikApi
        import asyncio
        client = AsyncOpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        async def main() -> None:
            await client.insights_views.update_insights_view(insights_view_id='insightsViewId', )
        asyncio.run(main())
        """
        _response = await self._raw_client.update_insights_view(
            insights_view_id,
            name=name,
            type=type,
            description=description,
            config=config,
            request_options=request_options,
        )
        return _response.data

    async def delete_insights_views_batch(
        self, *, ids: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete insights views batch

        Parameters
        ----------
        ids : typing.Sequence[str]

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

        Returns
        -------
        None

        Examples
        --------
        from Opik import AsyncOpikApi
        import asyncio
        client = AsyncOpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        async def main() -> None:
            await client.insights_views.delete_insights_views_batch(ids=['ids'], )
        asyncio.run(main())
        """
        _response = await self._raw_client.delete_insights_views_batch(ids=ids, request_options=request_options)
        return _response.data
