# 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.inline_response_2007 import InlineResponse2007
from ..types.v_1_trailer_assignments_response import V1TrailerAssignmentsResponse
from .raw_client import AsyncRawTrailerAssignmentsClient, RawTrailerAssignmentsClient


class TrailerAssignmentsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawTrailerAssignmentsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawTrailerAssignmentsClient
        """
        return self._raw_client

    def v_1_get_all_trailer_assignments(
        self,
        *,
        start_ms: typing.Optional[int] = None,
        end_ms: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        starting_after: typing.Optional[str] = None,
        ending_before: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> InlineResponse2007:
        """
        <n class="warning">
        <nh>
        <i class="fa fa-exclamation-circle"></i>
        This endpoint is still on our legacy API.
        </nh>
        </n>

        Fetch trailer assignment data for all trailers in your organization.

         <b>Rate limit:</b> 25 requests/sec (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</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.

        To use this endpoint, select **Read Assignments** under the Assignments 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>

        Parameters
        ----------
        start_ms : typing.Optional[int]
            Timestamp in Unix epoch miliseconds representing the start of the period to fetch. Omitting both startMs and endMs only returns current assignments.

        end_ms : typing.Optional[int]
            Timestamp in Unix epoch miliseconds representing the end of the period to fetch. Omitting endMs sets endMs as the current time

        limit : typing.Optional[int]
            Pagination parameter indicating the number of results to return in this request. Used in conjunction with either 'startingAfter' or 'endingBefore'.

        starting_after : typing.Optional[str]
            Pagination parameter indicating the cursor position to continue returning results after. Used in conjunction with the 'limit' parameter. Mutually exclusive with 'endingBefore' parameter.

        ending_before : typing.Optional[str]
            Pagination parameter indicating the cursor position to return results before. Used in conjunction with the 'limit' parameter. Mutually exclusive with 'startingAfter' parameter.

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

        Returns
        -------
        InlineResponse2007
            Returns trailer assignment data for all trailers in your organization

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.trailer_assignments.v_1_get_all_trailer_assignments()
        """
        _response = self._raw_client.v_1_get_all_trailer_assignments(
            start_ms=start_ms,
            end_ms=end_ms,
            limit=limit,
            starting_after=starting_after,
            ending_before=ending_before,
            request_options=request_options,
        )
        return _response.data

    def v_1_get_fleet_trailer_assignments(
        self,
        trailer_id: int,
        *,
        start_ms: typing.Optional[int] = None,
        end_ms: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> V1TrailerAssignmentsResponse:
        """
        <n class="warning">
        <nh>
        <i class="fa fa-exclamation-circle"></i>
        This endpoint is still on our legacy API.
        </nh>
        </n>

        Fetch trailer assignment data for a single trailer.

         <b>Rate limit:</b> 25 requests/sec (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</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.

        To use this endpoint, select **Read Assignments** under the Assignments 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>

        Parameters
        ----------
        trailer_id : int
            ID of trailer. Must contain only digits 0-9.

        start_ms : typing.Optional[int]
            Timestamp in Unix epoch milliseconds representing the start of the period to fetch. Omitting both startMs and endMs only returns current assignments.

        end_ms : typing.Optional[int]
            Timestamp in Unix epoch milliseconds representing the end of the period to fetch. Omitting endMs sets endMs as the current time

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

        Returns
        -------
        V1TrailerAssignmentsResponse
            Returns trailer assignment data for a single trailer

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.trailer_assignments.v_1_get_fleet_trailer_assignments(
            trailer_id=1000000,
        )
        """
        _response = self._raw_client.v_1_get_fleet_trailer_assignments(
            trailer_id, start_ms=start_ms, end_ms=end_ms, request_options=request_options
        )
        return _response.data


class AsyncTrailerAssignmentsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawTrailerAssignmentsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawTrailerAssignmentsClient
        """
        return self._raw_client

    async def v_1_get_all_trailer_assignments(
        self,
        *,
        start_ms: typing.Optional[int] = None,
        end_ms: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        starting_after: typing.Optional[str] = None,
        ending_before: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> InlineResponse2007:
        """
        <n class="warning">
        <nh>
        <i class="fa fa-exclamation-circle"></i>
        This endpoint is still on our legacy API.
        </nh>
        </n>

        Fetch trailer assignment data for all trailers in your organization.

         <b>Rate limit:</b> 25 requests/sec (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</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.

        To use this endpoint, select **Read Assignments** under the Assignments 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>

        Parameters
        ----------
        start_ms : typing.Optional[int]
            Timestamp in Unix epoch miliseconds representing the start of the period to fetch. Omitting both startMs and endMs only returns current assignments.

        end_ms : typing.Optional[int]
            Timestamp in Unix epoch miliseconds representing the end of the period to fetch. Omitting endMs sets endMs as the current time

        limit : typing.Optional[int]
            Pagination parameter indicating the number of results to return in this request. Used in conjunction with either 'startingAfter' or 'endingBefore'.

        starting_after : typing.Optional[str]
            Pagination parameter indicating the cursor position to continue returning results after. Used in conjunction with the 'limit' parameter. Mutually exclusive with 'endingBefore' parameter.

        ending_before : typing.Optional[str]
            Pagination parameter indicating the cursor position to return results before. Used in conjunction with the 'limit' parameter. Mutually exclusive with 'startingAfter' parameter.

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

        Returns
        -------
        InlineResponse2007
            Returns trailer assignment data for all trailers in your organization

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.trailer_assignments.v_1_get_all_trailer_assignments()


        asyncio.run(main())
        """
        _response = await self._raw_client.v_1_get_all_trailer_assignments(
            start_ms=start_ms,
            end_ms=end_ms,
            limit=limit,
            starting_after=starting_after,
            ending_before=ending_before,
            request_options=request_options,
        )
        return _response.data

    async def v_1_get_fleet_trailer_assignments(
        self,
        trailer_id: int,
        *,
        start_ms: typing.Optional[int] = None,
        end_ms: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> V1TrailerAssignmentsResponse:
        """
        <n class="warning">
        <nh>
        <i class="fa fa-exclamation-circle"></i>
        This endpoint is still on our legacy API.
        </nh>
        </n>

        Fetch trailer assignment data for a single trailer.

         <b>Rate limit:</b> 25 requests/sec (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</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.

        To use this endpoint, select **Read Assignments** under the Assignments 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>

        Parameters
        ----------
        trailer_id : int
            ID of trailer. Must contain only digits 0-9.

        start_ms : typing.Optional[int]
            Timestamp in Unix epoch milliseconds representing the start of the period to fetch. Omitting both startMs and endMs only returns current assignments.

        end_ms : typing.Optional[int]
            Timestamp in Unix epoch milliseconds representing the end of the period to fetch. Omitting endMs sets endMs as the current time

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

        Returns
        -------
        V1TrailerAssignmentsResponse
            Returns trailer assignment data for a single trailer

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.trailer_assignments.v_1_get_fleet_trailer_assignments(
                trailer_id=1000000,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.v_1_get_fleet_trailer_assignments(
            trailer_id, start_ms=start_ms, end_ms=end_ms, request_options=request_options
        )
        return _response.data
