# 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.carrier_proposed_assignment_response import CarrierProposedAssignmentResponse
from ..types.list_carrier_proposed_assignment_response import ListCarrierProposedAssignmentResponse
from .raw_client import AsyncRawCarrierProposedAssignmentsClient, RawCarrierProposedAssignmentsClient

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


class CarrierProposedAssignmentsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawCarrierProposedAssignmentsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawCarrierProposedAssignmentsClient
        """
        return self._raw_client

    def list_carrier_proposed_assignments(
        self,
        *,
        limit: typing.Optional[int] = None,
        after: typing.Optional[str] = None,
        driver_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        active_time: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListCarrierProposedAssignmentResponse:
        """
        Show the assignments created by the POST fleet/carrier-proposed-assignments. This endpoint will only show the assignments that are active for drivers and currently visible to them in the driver app. Once a proposed assignment has been accepted, the endpoint will not return any data.

         **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 Carrier-Proposed 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
        ----------
        limit : typing.Optional[int]
            The limit for how many objects will be in the response. Default and max for this value is 512 objects.

        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.

        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`

        active_time : typing.Optional[str]
            If specified, shows assignments that will be active at this time. Defaults to now, which would show current active assignments. In RFC 3339 format. Millisecond precision and timezones are supported. (Examples: 2019-06-13T19:08:25Z, 2019-06-13T19:08:25.455Z, OR 2015-09-15T14:00:12-04:00).

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

        Returns
        -------
        ListCarrierProposedAssignmentResponse
            Returns the assignments that drivers would see in the future, if any.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.carrier_proposed_assignments.list_carrier_proposed_assignments()
        """
        _response = self._raw_client.list_carrier_proposed_assignments(
            limit=limit, after=after, driver_ids=driver_ids, active_time=active_time, request_options=request_options
        )
        return _response.data

    def create_carrier_proposed_assignment(
        self,
        *,
        driver_id: str,
        vehicle_id: str,
        active_time: typing.Optional[str] = OMIT,
        shipping_docs: typing.Optional[str] = OMIT,
        trailer_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        trailer_names: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CarrierProposedAssignmentResponse:
        """
        Creates a new assignment that a driver can later use. Each driver can only have one future assignment.

         **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 **Write Carrier-Proposed 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
        ----------
        driver_id : str
            ID for the driver for the driver that this assignment is for. This can be either a unique Samsara ID or an external ID for the driver.

        vehicle_id : str
            ID for the vehicle to propose. This can be either a unique Samsara ID or an external ID for the vehicle.

        active_time : typing.Optional[str]
            Time after which this assignment will be active and visible to the driver on the mobile app. Not setting it makes it active now. UTC timestamp in RFC 3339 format. Example: `2020-01-27T07:06:25Z`.

        shipping_docs : typing.Optional[str]
            Shipping Documents that this assignment will propose to the driver.

        trailer_ids : typing.Optional[typing.Sequence[str]]
            IDs of trailers to propose. This can be either a unique Samsara IDs or an external IDs for the trailers. (forbidden if trailerNames is set)

        trailer_names : typing.Optional[typing.Sequence[str]]
            Names of trailers to propose. (forbidden if trailerIds is set)

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

        Returns
        -------
        CarrierProposedAssignmentResponse
            Return the created assignment

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.carrier_proposed_assignments.create_carrier_proposed_assignment(
            driver_id="42",
            vehicle_id="123",
        )
        """
        _response = self._raw_client.create_carrier_proposed_assignment(
            driver_id=driver_id,
            vehicle_id=vehicle_id,
            active_time=active_time,
            shipping_docs=shipping_docs,
            trailer_ids=trailer_ids,
            trailer_names=trailer_names,
            request_options=request_options,
        )
        return _response.data


class AsyncCarrierProposedAssignmentsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawCarrierProposedAssignmentsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawCarrierProposedAssignmentsClient
        """
        return self._raw_client

    async def list_carrier_proposed_assignments(
        self,
        *,
        limit: typing.Optional[int] = None,
        after: typing.Optional[str] = None,
        driver_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        active_time: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListCarrierProposedAssignmentResponse:
        """
        Show the assignments created by the POST fleet/carrier-proposed-assignments. This endpoint will only show the assignments that are active for drivers and currently visible to them in the driver app. Once a proposed assignment has been accepted, the endpoint will not return any data.

         **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 Carrier-Proposed 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
        ----------
        limit : typing.Optional[int]
            The limit for how many objects will be in the response. Default and max for this value is 512 objects.

        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.

        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`

        active_time : typing.Optional[str]
            If specified, shows assignments that will be active at this time. Defaults to now, which would show current active assignments. In RFC 3339 format. Millisecond precision and timezones are supported. (Examples: 2019-06-13T19:08:25Z, 2019-06-13T19:08:25.455Z, OR 2015-09-15T14:00:12-04:00).

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

        Returns
        -------
        ListCarrierProposedAssignmentResponse
            Returns the assignments that drivers would see in the future, if any.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.carrier_proposed_assignments.list_carrier_proposed_assignments()


        asyncio.run(main())
        """
        _response = await self._raw_client.list_carrier_proposed_assignments(
            limit=limit, after=after, driver_ids=driver_ids, active_time=active_time, request_options=request_options
        )
        return _response.data

    async def create_carrier_proposed_assignment(
        self,
        *,
        driver_id: str,
        vehicle_id: str,
        active_time: typing.Optional[str] = OMIT,
        shipping_docs: typing.Optional[str] = OMIT,
        trailer_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        trailer_names: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CarrierProposedAssignmentResponse:
        """
        Creates a new assignment that a driver can later use. Each driver can only have one future assignment.

         **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 **Write Carrier-Proposed 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
        ----------
        driver_id : str
            ID for the driver for the driver that this assignment is for. This can be either a unique Samsara ID or an external ID for the driver.

        vehicle_id : str
            ID for the vehicle to propose. This can be either a unique Samsara ID or an external ID for the vehicle.

        active_time : typing.Optional[str]
            Time after which this assignment will be active and visible to the driver on the mobile app. Not setting it makes it active now. UTC timestamp in RFC 3339 format. Example: `2020-01-27T07:06:25Z`.

        shipping_docs : typing.Optional[str]
            Shipping Documents that this assignment will propose to the driver.

        trailer_ids : typing.Optional[typing.Sequence[str]]
            IDs of trailers to propose. This can be either a unique Samsara IDs or an external IDs for the trailers. (forbidden if trailerNames is set)

        trailer_names : typing.Optional[typing.Sequence[str]]
            Names of trailers to propose. (forbidden if trailerIds is set)

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

        Returns
        -------
        CarrierProposedAssignmentResponse
            Return the created assignment

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.carrier_proposed_assignments.create_carrier_proposed_assignment(
                driver_id="42",
                vehicle_id="123",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_carrier_proposed_assignment(
            driver_id=driver_id,
            vehicle_id=vehicle_id,
            active_time=active_time,
            shipping_docs=shipping_docs,
            trailer_ids=trailer_ids,
            trailer_names=trailer_names,
            request_options=request_options,
        )
        return _response.data
