# 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.trailer_assignments_create_driver_trailer_assignment_response_body import (
    TrailerAssignmentsCreateDriverTrailerAssignmentResponseBody,
)
from ..types.trailer_assignments_get_driver_trailer_assignments_response_body import (
    TrailerAssignmentsGetDriverTrailerAssignmentsResponseBody,
)
from ..types.trailer_assignments_update_driver_trailer_assignment_response_body import (
    TrailerAssignmentsUpdateDriverTrailerAssignmentResponseBody,
)
from .raw_client import AsyncRawDriverTrailerAssignmentsClient, RawDriverTrailerAssignmentsClient

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class DriverTrailerAssignmentsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawDriverTrailerAssignmentsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawDriverTrailerAssignmentsClient
        """
        return self._raw_client

    def get_driver_trailer_assignments(
        self,
        *,
        driver_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        after: typing.Optional[str] = None,
        include_external_ids: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TrailerAssignmentsGetDriverTrailerAssignmentsResponseBody:
        """
        Get currently active driver-trailer assignments for driver.

         <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 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>


         **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
        ----------
        driver_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
             A filter on the data based on this comma-separated list of driver IDs and externalIds. Example: `driverIds=1234,5678,payroll:4841`

        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.

        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
        -------
        TrailerAssignmentsGetDriverTrailerAssignmentsResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.driver_trailer_assignments.get_driver_trailer_assignments()
        """
        _response = self._raw_client.get_driver_trailer_assignments(
            driver_ids=driver_ids,
            after=after,
            include_external_ids=include_external_ids,
            request_options=request_options,
        )
        return _response.data

    def create_driver_trailer_assignment(
        self,
        *,
        driver_id: str,
        trailer_id: str,
        start_time: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TrailerAssignmentsCreateDriverTrailerAssignmentResponseBody:
        """
        Create a new driver-trailer assignment

         <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 **Write 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>


         **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
        ----------
        driver_id : str
            ID of the driver. This can be either a unique Samsara ID or an [external ID](https://developers.samsara.com/docs/external-ids) for the driver.

        trailer_id : str
            ID of the trailer. This can be either a unique Samsara ID or an [external ID](https://developers.samsara.com/docs/external-ids) for the trailer.

        start_time : typing.Optional[str]
            The start time in RFC 3339 format. The time needs to be current or within the past 7 days. Defaults to now if not provided

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

        Returns
        -------
        TrailerAssignmentsCreateDriverTrailerAssignmentResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.driver_trailer_assignments.create_driver_trailer_assignment(
            driver_id="494123",
            trailer_id="12345",
        )
        """
        _response = self._raw_client.create_driver_trailer_assignment(
            driver_id=driver_id, trailer_id=trailer_id, start_time=start_time, request_options=request_options
        )
        return _response.data

    def update_driver_trailer_assignment(
        self, *, id: str, end_time: str, request_options: typing.Optional[RequestOptions] = None
    ) -> TrailerAssignmentsUpdateDriverTrailerAssignmentResponseBody:
        """
        Update an existing driver-trailer assignment.

         <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 **Write 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>


         **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
        ----------
        id : str
            Samsara ID for the assignment.

        end_time : str
            The end time in RFC 3339 format. The end time should not be in the future

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

        Returns
        -------
        TrailerAssignmentsUpdateDriverTrailerAssignmentResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.driver_trailer_assignments.update_driver_trailer_assignment(
            id="id",
            end_time="2019-06-13T19:08:25Z",
        )
        """
        _response = self._raw_client.update_driver_trailer_assignment(
            id=id, end_time=end_time, request_options=request_options
        )
        return _response.data


class AsyncDriverTrailerAssignmentsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawDriverTrailerAssignmentsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawDriverTrailerAssignmentsClient
        """
        return self._raw_client

    async def get_driver_trailer_assignments(
        self,
        *,
        driver_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        after: typing.Optional[str] = None,
        include_external_ids: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TrailerAssignmentsGetDriverTrailerAssignmentsResponseBody:
        """
        Get currently active driver-trailer assignments for driver.

         <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 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>


         **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
        ----------
        driver_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
             A filter on the data based on this comma-separated list of driver IDs and externalIds. Example: `driverIds=1234,5678,payroll:4841`

        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.

        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
        -------
        TrailerAssignmentsGetDriverTrailerAssignmentsResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.driver_trailer_assignments.get_driver_trailer_assignments()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_driver_trailer_assignments(
            driver_ids=driver_ids,
            after=after,
            include_external_ids=include_external_ids,
            request_options=request_options,
        )
        return _response.data

    async def create_driver_trailer_assignment(
        self,
        *,
        driver_id: str,
        trailer_id: str,
        start_time: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TrailerAssignmentsCreateDriverTrailerAssignmentResponseBody:
        """
        Create a new driver-trailer assignment

         <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 **Write 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>


         **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
        ----------
        driver_id : str
            ID of the driver. This can be either a unique Samsara ID or an [external ID](https://developers.samsara.com/docs/external-ids) for the driver.

        trailer_id : str
            ID of the trailer. This can be either a unique Samsara ID or an [external ID](https://developers.samsara.com/docs/external-ids) for the trailer.

        start_time : typing.Optional[str]
            The start time in RFC 3339 format. The time needs to be current or within the past 7 days. Defaults to now if not provided

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

        Returns
        -------
        TrailerAssignmentsCreateDriverTrailerAssignmentResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.driver_trailer_assignments.create_driver_trailer_assignment(
                driver_id="494123",
                trailer_id="12345",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_driver_trailer_assignment(
            driver_id=driver_id, trailer_id=trailer_id, start_time=start_time, request_options=request_options
        )
        return _response.data

    async def update_driver_trailer_assignment(
        self, *, id: str, end_time: str, request_options: typing.Optional[RequestOptions] = None
    ) -> TrailerAssignmentsUpdateDriverTrailerAssignmentResponseBody:
        """
        Update an existing driver-trailer assignment.

         <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 **Write 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>


         **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
        ----------
        id : str
            Samsara ID for the assignment.

        end_time : str
            The end time in RFC 3339 format. The end time should not be in the future

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

        Returns
        -------
        TrailerAssignmentsUpdateDriverTrailerAssignmentResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.driver_trailer_assignments.update_driver_trailer_assignment(
                id="id",
                end_time="2019-06-13T19:08:25Z",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_driver_trailer_assignment(
            id=id, end_time=end_time, request_options=request_options
        )
        return _response.data
