# 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.collect_status_response import CollectStatusResponse
from ..types.format import Format
from .raw_client import AsyncRawObservabilityClient, RawObservabilityClient
from .types.fetch_trace_by_id_request_trace_id import FetchTraceByIdRequestTraceId
from .types.fetch_trace_by_id_response import FetchTraceByIdResponse
from .types.query_analytics_response import QueryAnalyticsResponse
from .types.query_traces_response import QueryTracesResponse


class ObservabilityClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawObservabilityClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawObservabilityClient
        """
        return self._raw_client

    def otlp_v_1_traces(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> CollectStatusResponse:
        """
        Receive traces via OTLP.

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

        Returns
        -------
        CollectStatusResponse
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.observability.otlp_v_1_traces()
        """
        _response = self._raw_client.otlp_v_1_traces(request_options=request_options)
        return _response.data

    def otlp_status(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> CollectStatusResponse:
        """
        Status of OTLP endpoint.

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

        Returns
        -------
        CollectStatusResponse
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.observability.otlp_status()
        """
        _response = self._raw_client.otlp_status(request_options=request_options)
        return _response.data

    def otlp_receiver(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> CollectStatusResponse:
        """
        Receive traces via OTLP.

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

        Returns
        -------
        CollectStatusResponse
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.observability.otlp_receiver()
        """
        _response = self._raw_client.otlp_receiver(request_options=request_options)
        return _response.data

    def query_traces(
        self,
        *,
        format: typing.Optional[Format] = None,
        focus: typing.Optional[str] = None,
        oldest: typing.Optional[str] = None,
        newest: typing.Optional[str] = None,
        filtering: typing.Optional[str] = None,
        page: typing.Optional[int] = None,
        size: typing.Optional[int] = None,
        next: typing.Optional[str] = None,
        stop: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> QueryTracesResponse:
        """
        Query traces, with optional grouping, windowing, filtering, and pagination.

        Parameters
        ----------
        format : typing.Optional[Format]

        focus : typing.Optional[str]

        oldest : typing.Optional[str]

        newest : typing.Optional[str]

        filtering : typing.Optional[str]

        page : typing.Optional[int]

        size : typing.Optional[int]

        next : typing.Optional[str]

        stop : typing.Optional[str]

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

        Returns
        -------
        QueryTracesResponse
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.observability.query_traces()
        """
        _response = self._raw_client.query_traces(
            format=format,
            focus=focus,
            oldest=oldest,
            newest=newest,
            filtering=filtering,
            page=page,
            size=size,
            next=next,
            stop=stop,
            request_options=request_options,
        )
        return _response.data

    def delete_traces(
        self,
        *,
        node_id: typing.Optional[str] = None,
        node_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CollectStatusResponse:
        """
        Delete trace.

        Parameters
        ----------
        node_id : typing.Optional[str]

        node_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]

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

        Returns
        -------
        CollectStatusResponse
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.observability.delete_traces()
        """
        _response = self._raw_client.delete_traces(
            node_id=node_id, node_ids=node_ids, request_options=request_options
        )
        return _response.data

    def query_analytics(
        self,
        *,
        format: typing.Optional[Format] = None,
        focus: typing.Optional[str] = None,
        oldest: typing.Optional[str] = None,
        newest: typing.Optional[str] = None,
        window: typing.Optional[int] = None,
        filtering: typing.Optional[str] = None,
        time_range: typing.Optional[str] = None,
        app_id: typing.Optional[str] = None,
        environment: typing.Optional[str] = None,
        variant: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> QueryAnalyticsResponse:
        """
        Parameters
        ----------
        format : typing.Optional[Format]

        focus : typing.Optional[str]

        oldest : typing.Optional[str]

        newest : typing.Optional[str]

        window : typing.Optional[int]

        filtering : typing.Optional[str]

        time_range : typing.Optional[str]

        app_id : typing.Optional[str]

        environment : typing.Optional[str]

        variant : typing.Optional[str]

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

        Returns
        -------
        QueryAnalyticsResponse
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.observability.query_analytics()
        """
        _response = self._raw_client.query_analytics(
            format=format,
            focus=focus,
            oldest=oldest,
            newest=newest,
            window=window,
            filtering=filtering,
            time_range=time_range,
            app_id=app_id,
            environment=environment,
            variant=variant,
            request_options=request_options,
        )
        return _response.data

    def fetch_trace_by_id(
        self,
        trace_id: FetchTraceByIdRequestTraceId,
        *,
        format: typing.Optional[Format] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FetchTraceByIdResponse:
        """
        Fetch trace by ID.

        Parameters
        ----------
        trace_id : FetchTraceByIdRequestTraceId

        format : typing.Optional[Format]

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

        Returns
        -------
        FetchTraceByIdResponse
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.observability.fetch_trace_by_id(
            trace_id="trace_id",
        )
        """
        _response = self._raw_client.fetch_trace_by_id(
            trace_id, format=format, request_options=request_options
        )
        return _response.data


class AsyncObservabilityClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawObservabilityClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawObservabilityClient
        """
        return self._raw_client

    async def otlp_v_1_traces(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> CollectStatusResponse:
        """
        Receive traces via OTLP.

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

        Returns
        -------
        CollectStatusResponse
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.observability.otlp_v_1_traces()


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

    async def otlp_status(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> CollectStatusResponse:
        """
        Status of OTLP endpoint.

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

        Returns
        -------
        CollectStatusResponse
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.observability.otlp_status()


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

    async def otlp_receiver(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> CollectStatusResponse:
        """
        Receive traces via OTLP.

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

        Returns
        -------
        CollectStatusResponse
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.observability.otlp_receiver()


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

    async def query_traces(
        self,
        *,
        format: typing.Optional[Format] = None,
        focus: typing.Optional[str] = None,
        oldest: typing.Optional[str] = None,
        newest: typing.Optional[str] = None,
        filtering: typing.Optional[str] = None,
        page: typing.Optional[int] = None,
        size: typing.Optional[int] = None,
        next: typing.Optional[str] = None,
        stop: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> QueryTracesResponse:
        """
        Query traces, with optional grouping, windowing, filtering, and pagination.

        Parameters
        ----------
        format : typing.Optional[Format]

        focus : typing.Optional[str]

        oldest : typing.Optional[str]

        newest : typing.Optional[str]

        filtering : typing.Optional[str]

        page : typing.Optional[int]

        size : typing.Optional[int]

        next : typing.Optional[str]

        stop : typing.Optional[str]

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

        Returns
        -------
        QueryTracesResponse
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.observability.query_traces()


        asyncio.run(main())
        """
        _response = await self._raw_client.query_traces(
            format=format,
            focus=focus,
            oldest=oldest,
            newest=newest,
            filtering=filtering,
            page=page,
            size=size,
            next=next,
            stop=stop,
            request_options=request_options,
        )
        return _response.data

    async def delete_traces(
        self,
        *,
        node_id: typing.Optional[str] = None,
        node_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CollectStatusResponse:
        """
        Delete trace.

        Parameters
        ----------
        node_id : typing.Optional[str]

        node_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]

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

        Returns
        -------
        CollectStatusResponse
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.observability.delete_traces()


        asyncio.run(main())
        """
        _response = await self._raw_client.delete_traces(
            node_id=node_id, node_ids=node_ids, request_options=request_options
        )
        return _response.data

    async def query_analytics(
        self,
        *,
        format: typing.Optional[Format] = None,
        focus: typing.Optional[str] = None,
        oldest: typing.Optional[str] = None,
        newest: typing.Optional[str] = None,
        window: typing.Optional[int] = None,
        filtering: typing.Optional[str] = None,
        time_range: typing.Optional[str] = None,
        app_id: typing.Optional[str] = None,
        environment: typing.Optional[str] = None,
        variant: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> QueryAnalyticsResponse:
        """
        Parameters
        ----------
        format : typing.Optional[Format]

        focus : typing.Optional[str]

        oldest : typing.Optional[str]

        newest : typing.Optional[str]

        window : typing.Optional[int]

        filtering : typing.Optional[str]

        time_range : typing.Optional[str]

        app_id : typing.Optional[str]

        environment : typing.Optional[str]

        variant : typing.Optional[str]

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

        Returns
        -------
        QueryAnalyticsResponse
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.observability.query_analytics()


        asyncio.run(main())
        """
        _response = await self._raw_client.query_analytics(
            format=format,
            focus=focus,
            oldest=oldest,
            newest=newest,
            window=window,
            filtering=filtering,
            time_range=time_range,
            app_id=app_id,
            environment=environment,
            variant=variant,
            request_options=request_options,
        )
        return _response.data

    async def fetch_trace_by_id(
        self,
        trace_id: FetchTraceByIdRequestTraceId,
        *,
        format: typing.Optional[Format] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FetchTraceByIdResponse:
        """
        Fetch trace by ID.

        Parameters
        ----------
        trace_id : FetchTraceByIdRequestTraceId

        format : typing.Optional[Format]

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

        Returns
        -------
        FetchTraceByIdResponse
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.observability.fetch_trace_by_id(
                trace_id="trace_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.fetch_trace_by_id(
            trace_id, format=format, request_options=request_options
        )
        return _response.data
