# 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.logs_filter_query import LogsFilterQuery
from ...types.logs_response import LogsResponse
from .raw_client import AsyncRawBuildLogsClient, RawBuildLogsClient


class BuildLogsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawBuildLogsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawBuildLogsClient
        """
        return self._raw_client

    def get(
        self,
        pipeline_run_name: str,
        *,
        start_ts: typing.Optional[str] = None,
        end_ts: typing.Optional[str] = None,
        limit: typing.Optional[str] = None,
        direction: typing.Optional[str] = None,
        filter_query: typing.Optional[LogsFilterQuery] = None,
        num_logs_to_ignore: typing.Optional[float] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> LogsResponse:
        """
        Get logs for a given pipeline run by its name, with optional filters and time range.

        Parameters
        ----------
        pipeline_run_name : str
            PipelineRun Name

        start_ts : typing.Optional[str]
            Start timestamp for querying logs, in nanoseconds from the Unix epoch.

        end_ts : typing.Optional[str]
            End timestamp for querying logs, in nanoseconds from the Unix epoch.

        limit : typing.Optional[str]
            Max number of log lines to fetch

        direction : typing.Optional[str]
            Direction of sorting logs. Can be `asc` or `desc`

        filter_query : typing.Optional[LogsFilterQuery]
            Query to filter logs

        num_logs_to_ignore : typing.Optional[float]
            Number of logs corresponding to the starting timestamp to be ignored.

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

        Returns
        -------
        LogsResponse
            Successfully retrieved build logs for the pipeline run

        Examples
        --------
        from truefoundry_sdk import TrueFoundry

        client = TrueFoundry(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )
        client.internal.build_logs.get(
            pipeline_run_name="pipelineRunName",
            start_ts="1635467890123456789",
            end_ts="1635467891123456789",
            limit="limit",
            direction="direction",
            num_logs_to_ignore=1.1,
        )
        """
        _response = self._raw_client.get(
            pipeline_run_name,
            start_ts=start_ts,
            end_ts=end_ts,
            limit=limit,
            direction=direction,
            filter_query=filter_query,
            num_logs_to_ignore=num_logs_to_ignore,
            request_options=request_options,
        )
        return _response.data


class AsyncBuildLogsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawBuildLogsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawBuildLogsClient
        """
        return self._raw_client

    async def get(
        self,
        pipeline_run_name: str,
        *,
        start_ts: typing.Optional[str] = None,
        end_ts: typing.Optional[str] = None,
        limit: typing.Optional[str] = None,
        direction: typing.Optional[str] = None,
        filter_query: typing.Optional[LogsFilterQuery] = None,
        num_logs_to_ignore: typing.Optional[float] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> LogsResponse:
        """
        Get logs for a given pipeline run by its name, with optional filters and time range.

        Parameters
        ----------
        pipeline_run_name : str
            PipelineRun Name

        start_ts : typing.Optional[str]
            Start timestamp for querying logs, in nanoseconds from the Unix epoch.

        end_ts : typing.Optional[str]
            End timestamp for querying logs, in nanoseconds from the Unix epoch.

        limit : typing.Optional[str]
            Max number of log lines to fetch

        direction : typing.Optional[str]
            Direction of sorting logs. Can be `asc` or `desc`

        filter_query : typing.Optional[LogsFilterQuery]
            Query to filter logs

        num_logs_to_ignore : typing.Optional[float]
            Number of logs corresponding to the starting timestamp to be ignored.

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

        Returns
        -------
        LogsResponse
            Successfully retrieved build logs for the pipeline run

        Examples
        --------
        import asyncio

        from truefoundry_sdk import AsyncTrueFoundry

        client = AsyncTrueFoundry(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.internal.build_logs.get(
                pipeline_run_name="pipelineRunName",
                start_ts="1635467890123456789",
                end_ts="1635467891123456789",
                limit="limit",
                direction="direction",
                num_logs_to_ignore=1.1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get(
            pipeline_run_name,
            start_ts=start_ts,
            end_ts=end_ts,
            limit=limit,
            direction=direction,
            filter_query=filter_query,
            num_logs_to_ignore=num_logs_to_ignore,
            request_options=request_options,
        )
        return _response.data
