# 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.routes_get_route_events_stream_response_body import RoutesGetRouteEventsStreamResponseBody
from .raw_client import AsyncRawRouteEventsClient, RawRouteEventsClient


class RouteEventsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawRouteEventsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawRouteEventsClient
        """
        return self._raw_client

    def get_route_events_stream(
        self,
        *,
        after: typing.Optional[str] = None,
        start_time: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        include_external_ids: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RoutesGetRouteEventsStreamResponseBody:
        """
        Subscribes to a feed of immutable, append-only updates for routes. The initial request to this feed endpoint returns a cursor, which can be used in subsequent requests to fetch events on all routes that occurred after the last retrieved event. An initial request (with empty after and startTime parameters) will return events from the past 24 hours.

         <b>Rate limit:</b> 5 requests/sec (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Read Routes** under the Driver Workflow category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        after : typing.Optional[str]
             If specified, this should be the endCursor value from the previous page of results. When present, this request will return the next page of results that occur immediately after the previous page of results.

        start_time : typing.Optional[str]
            A start time in RFC 3339 format. Defaults to 24 hours ago if not provided. Millisecond precision and timezones are supported. (Examples: 2025-07-01T19:08:25Z, 2025-07-01T19:08:25.455Z, OR 2025-07-01T14:00:12-04:00). Cannot be more than 7 days in the past.

        limit : typing.Optional[int]
            The limit for how many events will be in the response. Default and max for this value is 200 events.

        include_external_ids : typing.Optional[bool]
            Optional boolean indicating whether to return external IDs on supported entities

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

        Returns
        -------
        RoutesGetRouteEventsStreamResponseBody
            OK response.

        Examples
        --------
        from samsara import Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.route_events.get_route_events_stream()
        """
        _response = self._raw_client.get_route_events_stream(
            after=after,
            start_time=start_time,
            limit=limit,
            include_external_ids=include_external_ids,
            request_options=request_options,
        )
        return _response.data


class AsyncRouteEventsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawRouteEventsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawRouteEventsClient
        """
        return self._raw_client

    async def get_route_events_stream(
        self,
        *,
        after: typing.Optional[str] = None,
        start_time: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        include_external_ids: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RoutesGetRouteEventsStreamResponseBody:
        """
        Subscribes to a feed of immutable, append-only updates for routes. The initial request to this feed endpoint returns a cursor, which can be used in subsequent requests to fetch events on all routes that occurred after the last retrieved event. An initial request (with empty after and startTime parameters) will return events from the past 24 hours.

         <b>Rate limit:</b> 5 requests/sec (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Read Routes** under the Driver Workflow category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        after : typing.Optional[str]
             If specified, this should be the endCursor value from the previous page of results. When present, this request will return the next page of results that occur immediately after the previous page of results.

        start_time : typing.Optional[str]
            A start time in RFC 3339 format. Defaults to 24 hours ago if not provided. Millisecond precision and timezones are supported. (Examples: 2025-07-01T19:08:25Z, 2025-07-01T19:08:25.455Z, OR 2025-07-01T14:00:12-04:00). Cannot be more than 7 days in the past.

        limit : typing.Optional[int]
            The limit for how many events will be in the response. Default and max for this value is 200 events.

        include_external_ids : typing.Optional[bool]
            Optional boolean indicating whether to return external IDs on supported entities

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

        Returns
        -------
        RoutesGetRouteEventsStreamResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.route_events.get_route_events_stream()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_route_events_stream(
            after=after,
            start_time=start_time,
            limit=limit,
            include_external_ids=include_external_ids,
            request_options=request_options,
        )
        return _response.data
