# 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.json_node_public import JsonNodePublic
from ..types.json_node_write import JsonNodeWrite
from .raw_client import AsyncRawDashboardsClient, RawDashboardsClient
from .types.dashboard_update_public_scope import DashboardUpdatePublicScope
from .types.dashboard_update_public_type import DashboardUpdatePublicType
from .types.dashboard_write_scope import DashboardWriteScope
from .types.dashboard_write_type import DashboardWriteType

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


class DashboardsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawDashboardsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawDashboardsClient
        """
        return self._raw_client

    def find_dashboards(
        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 dashboards 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
            Dashboard page

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

    def create_dashboard(
        self,
        *,
        name: str,
        config: JsonNodeWrite,
        project_id: typing.Optional[str] = OMIT,
        project_name: typing.Optional[str] = OMIT,
        type: typing.Optional[DashboardWriteType] = OMIT,
        scope: typing.Optional[DashboardWriteScope] = OMIT,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DashboardPublic:
        """
        Create a new dashboard 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]

        scope : typing.Optional[DashboardWriteScope]

        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.dashboards.create_dashboard(name='name', config={'key': 'value'
        }, )
        """
        _response = self._raw_client.create_dashboard(
            name=name,
            config=config,
            project_id=project_id,
            project_name=project_name,
            type=type,
            scope=scope,
            description=description,
            request_options=request_options,
        )
        return _response.data

    def get_dashboard_by_id(
        self, dashboard_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DashboardPublic:
        """
        Get dashboard by id

        Parameters
        ----------
        dashboard_id : str

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

        Returns
        -------
        DashboardPublic
            Dashboard resource

        Examples
        --------
        from Opik import OpikApi
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.dashboards.get_dashboard_by_id(dashboard_id='dashboardId', )
        """
        _response = self._raw_client.get_dashboard_by_id(dashboard_id, request_options=request_options)
        return _response.data

    def delete_dashboard(self, dashboard_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Delete dashboard by id

        Parameters
        ----------
        dashboard_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.dashboards.delete_dashboard(dashboard_id='dashboardId', )
        """
        _response = self._raw_client.delete_dashboard(dashboard_id, request_options=request_options)
        return _response.data

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

        Parameters
        ----------
        dashboard_id : str

        name : typing.Optional[str]

        type : typing.Optional[DashboardUpdatePublicType]

        scope : typing.Optional[DashboardUpdatePublicScope]

        description : typing.Optional[str]

        config : typing.Optional[JsonNodePublic]

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

        Returns
        -------
        DashboardPublic
            Updated dashboard

        Examples
        --------
        from Opik import OpikApi
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.dashboards.update_dashboard(dashboard_id='dashboardId', )
        """
        _response = self._raw_client.update_dashboard(
            dashboard_id,
            name=name,
            type=type,
            scope=scope,
            description=description,
            config=config,
            request_options=request_options,
        )
        return _response.data

    def delete_dashboards_batch(
        self, *, ids: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete dashboards 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.dashboards.delete_dashboards_batch(ids=['ids'], )
        """
        _response = self._raw_client.delete_dashboards_batch(ids=ids, request_options=request_options)
        return _response.data


class AsyncDashboardsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawDashboardsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawDashboardsClient
        """
        return self._raw_client

    async def find_dashboards(
        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 dashboards 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
            Dashboard 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.dashboards.find_dashboards()
        asyncio.run(main())
        """
        _response = await self._raw_client.find_dashboards(
            page=page,
            size=size,
            name=name,
            project_id=project_id,
            sorting=sorting,
            filters=filters,
            request_options=request_options,
        )
        return _response.data

    async def create_dashboard(
        self,
        *,
        name: str,
        config: JsonNodeWrite,
        project_id: typing.Optional[str] = OMIT,
        project_name: typing.Optional[str] = OMIT,
        type: typing.Optional[DashboardWriteType] = OMIT,
        scope: typing.Optional[DashboardWriteScope] = OMIT,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DashboardPublic:
        """
        Create a new dashboard 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]

        scope : typing.Optional[DashboardWriteScope]

        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.dashboards.create_dashboard(name='name', config={'key': 'value'
            }, )
        asyncio.run(main())
        """
        _response = await self._raw_client.create_dashboard(
            name=name,
            config=config,
            project_id=project_id,
            project_name=project_name,
            type=type,
            scope=scope,
            description=description,
            request_options=request_options,
        )
        return _response.data

    async def get_dashboard_by_id(
        self, dashboard_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DashboardPublic:
        """
        Get dashboard by id

        Parameters
        ----------
        dashboard_id : str

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

        Returns
        -------
        DashboardPublic
            Dashboard 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.dashboards.get_dashboard_by_id(dashboard_id='dashboardId', )
        asyncio.run(main())
        """
        _response = await self._raw_client.get_dashboard_by_id(dashboard_id, request_options=request_options)
        return _response.data

    async def delete_dashboard(
        self, dashboard_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete dashboard by id

        Parameters
        ----------
        dashboard_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.dashboards.delete_dashboard(dashboard_id='dashboardId', )
        asyncio.run(main())
        """
        _response = await self._raw_client.delete_dashboard(dashboard_id, request_options=request_options)
        return _response.data

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

        Parameters
        ----------
        dashboard_id : str

        name : typing.Optional[str]

        type : typing.Optional[DashboardUpdatePublicType]

        scope : typing.Optional[DashboardUpdatePublicScope]

        description : typing.Optional[str]

        config : typing.Optional[JsonNodePublic]

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

        Returns
        -------
        DashboardPublic
            Updated dashboard

        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.dashboards.update_dashboard(dashboard_id='dashboardId', )
        asyncio.run(main())
        """
        _response = await self._raw_client.update_dashboard(
            dashboard_id,
            name=name,
            type=type,
            scope=scope,
            description=description,
            config=config,
            request_options=request_options,
        )
        return _response.data

    async def delete_dashboards_batch(
        self, *, ids: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete dashboards 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.dashboards.delete_dashboards_batch(ids=['ids'], )
        asyncio.run(main())
        """
        _response = await self._raw_client.delete_dashboards_batch(ids=ids, request_options=request_options)
        return _response.data
