# 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.speeding_intervals_get_speeding_intervals_response_body import (
    SpeedingIntervalsGetSpeedingIntervalsResponseBody,
)
from .raw_client import AsyncRawSpeedingIntervalsClient, RawSpeedingIntervalsClient
from .types.get_speeding_intervals_request_query_by import GetSpeedingIntervalsRequestQueryBy


class SpeedingIntervalsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawSpeedingIntervalsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawSpeedingIntervalsClient
        """
        return self._raw_client

    def get_speeding_intervals(
        self,
        *,
        start_time: str,
        asset_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        end_time: typing.Optional[str] = None,
        query_by: typing.Optional[GetSpeedingIntervalsRequestQueryBy] = None,
        include_asset: typing.Optional[bool] = None,
        include_driver_id: typing.Optional[bool] = None,
        after: typing.Optional[str] = None,
        severity_levels: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SpeedingIntervalsGetSpeedingIntervalsResponseBody:
        """
        This endpoint will return all speeding intervals associated with all trips that have been collected for your organization based on the time parameters passed in. Only completed trips are included. Trips with no speeding intervals detected will be returned with an empty list of intervals. Results are paginated.

         <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 Speeding Intervals** under the Speeding Intervals 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
        ----------
        start_time : str
            RFC 3339 timestamp that indicates when to begin receiving data. Value is compared against `updatedAtTime` or `tripStartTime` depending on the queryBy parameter.

        asset_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Comma-separated list of asset IDs. Include up to 50 asset IDs.

        end_time : typing.Optional[str]
            RFC 3339 timestamp which is compared against `updatedAtTime` or `tripStartTime` depending on the queryBy parameter. If not provided then the endpoint behaves as an unending feed of changes.

        query_by : typing.Optional[GetSpeedingIntervalsRequestQueryBy]
            Decide which timestamp the `startTime` and `endTime` are compared to.  Valid values: `updatedAtTime`, `tripStartTime`

        include_asset : typing.Optional[bool]
            Indicates whether or not to return expanded “asset” data

        include_driver_id : typing.Optional[bool]
            Indicates whether or not to return trip's driver id

        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.

        severity_levels : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma-separated severity levels to filter speeding intervals by. Valid values:  “light”, ”moderate”, ”heavy”, “severe”. This filter does not exclude trips that have no speeding intervals.

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

        Returns
        -------
        SpeedingIntervalsGetSpeedingIntervalsResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.speeding_intervals.get_speeding_intervals(
            start_time="startTime",
        )
        """
        _response = self._raw_client.get_speeding_intervals(
            start_time=start_time,
            asset_ids=asset_ids,
            end_time=end_time,
            query_by=query_by,
            include_asset=include_asset,
            include_driver_id=include_driver_id,
            after=after,
            severity_levels=severity_levels,
            request_options=request_options,
        )
        return _response.data


class AsyncSpeedingIntervalsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawSpeedingIntervalsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawSpeedingIntervalsClient
        """
        return self._raw_client

    async def get_speeding_intervals(
        self,
        *,
        start_time: str,
        asset_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        end_time: typing.Optional[str] = None,
        query_by: typing.Optional[GetSpeedingIntervalsRequestQueryBy] = None,
        include_asset: typing.Optional[bool] = None,
        include_driver_id: typing.Optional[bool] = None,
        after: typing.Optional[str] = None,
        severity_levels: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SpeedingIntervalsGetSpeedingIntervalsResponseBody:
        """
        This endpoint will return all speeding intervals associated with all trips that have been collected for your organization based on the time parameters passed in. Only completed trips are included. Trips with no speeding intervals detected will be returned with an empty list of intervals. Results are paginated.

         <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 Speeding Intervals** under the Speeding Intervals 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
        ----------
        start_time : str
            RFC 3339 timestamp that indicates when to begin receiving data. Value is compared against `updatedAtTime` or `tripStartTime` depending on the queryBy parameter.

        asset_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Comma-separated list of asset IDs. Include up to 50 asset IDs.

        end_time : typing.Optional[str]
            RFC 3339 timestamp which is compared against `updatedAtTime` or `tripStartTime` depending on the queryBy parameter. If not provided then the endpoint behaves as an unending feed of changes.

        query_by : typing.Optional[GetSpeedingIntervalsRequestQueryBy]
            Decide which timestamp the `startTime` and `endTime` are compared to.  Valid values: `updatedAtTime`, `tripStartTime`

        include_asset : typing.Optional[bool]
            Indicates whether or not to return expanded “asset” data

        include_driver_id : typing.Optional[bool]
            Indicates whether or not to return trip's driver id

        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.

        severity_levels : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma-separated severity levels to filter speeding intervals by. Valid values:  “light”, ”moderate”, ”heavy”, “severe”. This filter does not exclude trips that have no speeding intervals.

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

        Returns
        -------
        SpeedingIntervalsGetSpeedingIntervalsResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.speeding_intervals.get_speeding_intervals(
                start_time="startTime",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_speeding_intervals(
            start_time=start_time,
            asset_ids=asset_ids,
            end_time=end_time,
            query_by=query_by,
            include_asset=include_asset,
            include_driver_id=include_driver_id,
            after=after,
            severity_levels=severity_levels,
            request_options=request_options,
        )
        return _response.data
