# 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.defect_response import DefectResponse
from ..types.dvir_defect_get_defect_response_body import DvirDefectGetDefectResponseBody
from ..types.dvir_defect_stream_defects_response_body import DvirDefectStreamDefectsResponseBody
from ..types.dvir_defect_type_get_defect_types_response_body import DvirDefectTypeGetDefectTypesResponseBody
from ..types.dvir_get_dvir_response_body import DvirGetDvirResponseBody
from ..types.dvir_get_dvirs_response_body import DvirGetDvirsResponseBody
from ..types.dvir_response import DvirResponse
from ..types.inline_response_2004 import InlineResponse2004
from ..types.resolved_by import ResolvedBy
from .raw_client import AsyncRawMaintenanceClient, RawMaintenanceClient
from .types.create_dvir_request_safety_status import CreateDvirRequestSafetyStatus
from .types.create_dvir_request_type import CreateDvirRequestType

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


class MaintenanceClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawMaintenanceClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawMaintenanceClient
        """
        return self._raw_client

    def get_defect_types(
        self,
        *,
        after: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DvirDefectTypeGetDefectTypesResponseBody:
        """
        Get DVIR defect types.

         <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 Defect Types** under the Maintenance 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.

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

        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            A filter on the data based on this comma-separated list of defect type IDs.

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

        Returns
        -------
        DvirDefectTypeGetDefectTypesResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.maintenance.get_defect_types()
        """
        _response = self._raw_client.get_defect_types(
            after=after, limit=limit, ids=ids, request_options=request_options
        )
        return _response.data

    def stream_defects(
        self,
        *,
        start_time: str,
        after: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        end_time: typing.Optional[str] = None,
        include_external_ids: typing.Optional[bool] = None,
        is_resolved: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DvirDefectStreamDefectsResponseBody:
        """
        Stream DVIR defects.

         <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 Defects** under the Maintenance 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
            Required RFC 3339 timestamp to begin the feed or history by `updatedAtTime` at `startTime`.

        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.

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

        end_time : typing.Optional[str]
            Optional RFC 3339 timestamp. If not provided then the endpoint behaves as an unending feed of changes.

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

        is_resolved : typing.Optional[bool]
            Boolean value for whether filter defects by resolved status.

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

        Returns
        -------
        DvirDefectStreamDefectsResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.maintenance.stream_defects(
            start_time="startTime",
        )
        """
        _response = self._raw_client.stream_defects(
            start_time=start_time,
            after=after,
            limit=limit,
            end_time=end_time,
            include_external_ids=include_external_ids,
            is_resolved=is_resolved,
            request_options=request_options,
        )
        return _response.data

    def get_defect(
        self,
        id: str,
        *,
        include_external_ids: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DvirDefectGetDefectResponseBody:
        """
        Get a single DVIR defect by ID.

         <b>Rate limit:</b> 10 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 Defects** under the Maintenance 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
            The unique ID of the DVIR defect.

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

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.maintenance.get_defect(
            id="id",
        )
        """
        _response = self._raw_client.get_defect(
            id, include_external_ids=include_external_ids, request_options=request_options
        )
        return _response.data

    def get_dvirs(
        self,
        *,
        start_time: str,
        after: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        include_external_ids: typing.Optional[bool] = None,
        end_time: typing.Optional[str] = None,
        safety_status: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DvirGetDvirsResponseBody:
        """
        Returns a history/feed of changed DVIRs by updatedAtTime between startTime and endTime parameters. In case of missing `endTime` parameter it will return a never ending stream of data.

         <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 DVIRs** under the Maintenance 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
            Required RFC 3339 timestamp to begin the feed or history by `updatedAtTime` at `startTime`.

        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.

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

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

        end_time : typing.Optional[str]
            Optional RFC 3339 timestamp. If not provided then the endpoint behaves as an unending feed of changes.

        safety_status : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional list of safety statuses. Valid values: [safe, unsafe, resolved]

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

        Returns
        -------
        DvirGetDvirsResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.maintenance.get_dvirs(
            start_time="startTime",
        )
        """
        _response = self._raw_client.get_dvirs(
            start_time=start_time,
            after=after,
            limit=limit,
            include_external_ids=include_external_ids,
            end_time=end_time,
            safety_status=safety_status,
            request_options=request_options,
        )
        return _response.data

    def get_dvir(
        self,
        id: str,
        *,
        include_external_ids: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DvirGetDvirResponseBody:
        """
        Get a single DVIR by ID.

         <b>Rate limit:</b> 10 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 DVIRs** under the Maintenance 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
            Id of the DVIR.

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

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.maintenance.get_dvir(
            id="id",
        )
        """
        _response = self._raw_client.get_dvir(
            id, include_external_ids=include_external_ids, request_options=request_options
        )
        return _response.data

    def update_dvir_defect(
        self,
        id: str,
        *,
        is_resolved: typing.Optional[bool] = OMIT,
        mechanic_notes: typing.Optional[str] = OMIT,
        resolved_at_time: typing.Optional[str] = OMIT,
        resolved_by: typing.Optional[ResolvedBy] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DefectResponse:
        """
        Updates a given defect. Can be used to resolve a defect by marking its `isResolved` field to `true`.

         **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 Defects** under the Maintenance 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
        ----------
        id : str
            ID of the defect.

        is_resolved : typing.Optional[bool]
            Resolves the defect. Must be `true`.

        mechanic_notes : typing.Optional[str]
            The mechanics notes on the defect.

        resolved_at_time : typing.Optional[str]
            Time when defect was resolved. Defaults to now if not provided. UTC timestamp in RFC 3339 format. Example: `2020-01-27T07:06:25Z`.

        resolved_by : typing.Optional[ResolvedBy]

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

        Returns
        -------
        DefectResponse
            Return the modified defect entity

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.maintenance.update_dvir_defect(
            id="id",
        )
        """
        _response = self._raw_client.update_dvir_defect(
            id,
            is_resolved=is_resolved,
            mechanic_notes=mechanic_notes,
            resolved_at_time=resolved_at_time,
            resolved_by=resolved_by,
            request_options=request_options,
        )
        return _response.data

    def create_dvir(
        self,
        *,
        author_id: str,
        safety_status: CreateDvirRequestSafetyStatus,
        type: CreateDvirRequestType,
        license_plate: typing.Optional[str] = OMIT,
        location: typing.Optional[str] = OMIT,
        mechanic_notes: typing.Optional[str] = OMIT,
        odometer_meters: typing.Optional[int] = OMIT,
        resolved_defect_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        trailer_id: typing.Optional[str] = OMIT,
        vehicle_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DvirResponse:
        """
        Creates a new mechanic DVIR in the organization.

         **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 DVIRs** under the Maintenance 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
        ----------
        author_id : str
            Samsara user ID of the mechanic creating the DVIR.

        safety_status : CreateDvirRequestSafetyStatus
            Whether or not this vehicle or trailer is safe to drive.

        type : CreateDvirRequestType
            Only type 'mechanic' is currently accepted.

        license_plate : typing.Optional[str]
            The license plate of this vehicle.

        location : typing.Optional[str]
            Optional string if your jurisdiction requires a location of the DVIR.

        mechanic_notes : typing.Optional[str]
            The mechanics notes on the DVIR.

        odometer_meters : typing.Optional[int]
            The odometer reading in meters.

        resolved_defect_ids : typing.Optional[typing.Sequence[str]]
            Array of ids for defects being resolved with this DVIR.

        trailer_id : typing.Optional[str]
            Id of trailer being inspected. Either vehicleId or trailerId must be provided.

        vehicle_id : typing.Optional[str]
            Id of vehicle being inspected. Either vehicleId or trailerId must be provided.

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

        Returns
        -------
        DvirResponse
            Newly created DVIR.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.maintenance.create_dvir(
            author_id="11",
            safety_status="safe",
            type="mechanic",
        )
        """
        _response = self._raw_client.create_dvir(
            author_id=author_id,
            safety_status=safety_status,
            type=type,
            license_plate=license_plate,
            location=location,
            mechanic_notes=mechanic_notes,
            odometer_meters=odometer_meters,
            resolved_defect_ids=resolved_defect_ids,
            trailer_id=trailer_id,
            vehicle_id=vehicle_id,
            request_options=request_options,
        )
        return _response.data

    def update_dvir(
        self,
        id: str,
        *,
        author_id: str,
        is_resolved: bool,
        mechanic_notes: typing.Optional[str] = OMIT,
        signed_at_time: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DvirResponse:
        """
        Resolves a given DVIR by marking its `isResolved` field to `true`.

         **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 DVIRs** under the Maintenance 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
        ----------
        id : str
            ID of the DVIR.

        author_id : str
            The user who is resolving the dvir.

        is_resolved : bool
            Resolves the DVIR. Must be `true`.

        mechanic_notes : typing.Optional[str]
            The mechanics notes on the DVIR.

        signed_at_time : typing.Optional[str]
            Time when user signed this DVIR. Defaults to now. UTC timestamp in RFC 3339 format. Example: `2020-01-27T07:06:25Z`.

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

        Returns
        -------
        DvirResponse
            Updated dvir object with ID.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.maintenance.update_dvir(
            id="id",
            author_id="11",
            is_resolved=True,
        )
        """
        _response = self._raw_client.update_dvir(
            id,
            author_id=author_id,
            is_resolved=is_resolved,
            mechanic_notes=mechanic_notes,
            signed_at_time=signed_at_time,
            request_options=request_options,
        )
        return _response.data

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

        Get list of the vehicles with any engine faults or check light 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 DVIRs** under the Maintenance 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
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        InlineResponse2004
            List of vehicles and maintenance information about each.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.maintenance.v_1_get_fleet_maintenance_list()
        """
        _response = self._raw_client.v_1_get_fleet_maintenance_list(request_options=request_options)
        return _response.data


class AsyncMaintenanceClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawMaintenanceClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawMaintenanceClient
        """
        return self._raw_client

    async def get_defect_types(
        self,
        *,
        after: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DvirDefectTypeGetDefectTypesResponseBody:
        """
        Get DVIR defect types.

         <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 Defect Types** under the Maintenance 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.

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

        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            A filter on the data based on this comma-separated list of defect type IDs.

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

        Returns
        -------
        DvirDefectTypeGetDefectTypesResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.maintenance.get_defect_types()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_defect_types(
            after=after, limit=limit, ids=ids, request_options=request_options
        )
        return _response.data

    async def stream_defects(
        self,
        *,
        start_time: str,
        after: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        end_time: typing.Optional[str] = None,
        include_external_ids: typing.Optional[bool] = None,
        is_resolved: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DvirDefectStreamDefectsResponseBody:
        """
        Stream DVIR defects.

         <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 Defects** under the Maintenance 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
            Required RFC 3339 timestamp to begin the feed or history by `updatedAtTime` at `startTime`.

        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.

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

        end_time : typing.Optional[str]
            Optional RFC 3339 timestamp. If not provided then the endpoint behaves as an unending feed of changes.

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

        is_resolved : typing.Optional[bool]
            Boolean value for whether filter defects by resolved status.

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

        Returns
        -------
        DvirDefectStreamDefectsResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


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


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

    async def get_defect(
        self,
        id: str,
        *,
        include_external_ids: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DvirDefectGetDefectResponseBody:
        """
        Get a single DVIR defect by ID.

         <b>Rate limit:</b> 10 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 Defects** under the Maintenance 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
            The unique ID of the DVIR defect.

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

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.maintenance.get_defect(
                id="id",
            )


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

    async def get_dvirs(
        self,
        *,
        start_time: str,
        after: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        include_external_ids: typing.Optional[bool] = None,
        end_time: typing.Optional[str] = None,
        safety_status: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DvirGetDvirsResponseBody:
        """
        Returns a history/feed of changed DVIRs by updatedAtTime between startTime and endTime parameters. In case of missing `endTime` parameter it will return a never ending stream of data.

         <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 DVIRs** under the Maintenance 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
            Required RFC 3339 timestamp to begin the feed or history by `updatedAtTime` at `startTime`.

        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.

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

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

        end_time : typing.Optional[str]
            Optional RFC 3339 timestamp. If not provided then the endpoint behaves as an unending feed of changes.

        safety_status : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional list of safety statuses. Valid values: [safe, unsafe, resolved]

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

        Returns
        -------
        DvirGetDvirsResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


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


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

    async def get_dvir(
        self,
        id: str,
        *,
        include_external_ids: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DvirGetDvirResponseBody:
        """
        Get a single DVIR by ID.

         <b>Rate limit:</b> 10 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 DVIRs** under the Maintenance 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
            Id of the DVIR.

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

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.maintenance.get_dvir(
                id="id",
            )


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

    async def update_dvir_defect(
        self,
        id: str,
        *,
        is_resolved: typing.Optional[bool] = OMIT,
        mechanic_notes: typing.Optional[str] = OMIT,
        resolved_at_time: typing.Optional[str] = OMIT,
        resolved_by: typing.Optional[ResolvedBy] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DefectResponse:
        """
        Updates a given defect. Can be used to resolve a defect by marking its `isResolved` field to `true`.

         **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 Defects** under the Maintenance 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
        ----------
        id : str
            ID of the defect.

        is_resolved : typing.Optional[bool]
            Resolves the defect. Must be `true`.

        mechanic_notes : typing.Optional[str]
            The mechanics notes on the defect.

        resolved_at_time : typing.Optional[str]
            Time when defect was resolved. Defaults to now if not provided. UTC timestamp in RFC 3339 format. Example: `2020-01-27T07:06:25Z`.

        resolved_by : typing.Optional[ResolvedBy]

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

        Returns
        -------
        DefectResponse
            Return the modified defect entity

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.maintenance.update_dvir_defect(
                id="id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_dvir_defect(
            id,
            is_resolved=is_resolved,
            mechanic_notes=mechanic_notes,
            resolved_at_time=resolved_at_time,
            resolved_by=resolved_by,
            request_options=request_options,
        )
        return _response.data

    async def create_dvir(
        self,
        *,
        author_id: str,
        safety_status: CreateDvirRequestSafetyStatus,
        type: CreateDvirRequestType,
        license_plate: typing.Optional[str] = OMIT,
        location: typing.Optional[str] = OMIT,
        mechanic_notes: typing.Optional[str] = OMIT,
        odometer_meters: typing.Optional[int] = OMIT,
        resolved_defect_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        trailer_id: typing.Optional[str] = OMIT,
        vehicle_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DvirResponse:
        """
        Creates a new mechanic DVIR in the organization.

         **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 DVIRs** under the Maintenance 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
        ----------
        author_id : str
            Samsara user ID of the mechanic creating the DVIR.

        safety_status : CreateDvirRequestSafetyStatus
            Whether or not this vehicle or trailer is safe to drive.

        type : CreateDvirRequestType
            Only type 'mechanic' is currently accepted.

        license_plate : typing.Optional[str]
            The license plate of this vehicle.

        location : typing.Optional[str]
            Optional string if your jurisdiction requires a location of the DVIR.

        mechanic_notes : typing.Optional[str]
            The mechanics notes on the DVIR.

        odometer_meters : typing.Optional[int]
            The odometer reading in meters.

        resolved_defect_ids : typing.Optional[typing.Sequence[str]]
            Array of ids for defects being resolved with this DVIR.

        trailer_id : typing.Optional[str]
            Id of trailer being inspected. Either vehicleId or trailerId must be provided.

        vehicle_id : typing.Optional[str]
            Id of vehicle being inspected. Either vehicleId or trailerId must be provided.

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

        Returns
        -------
        DvirResponse
            Newly created DVIR.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.maintenance.create_dvir(
                author_id="11",
                safety_status="safe",
                type="mechanic",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_dvir(
            author_id=author_id,
            safety_status=safety_status,
            type=type,
            license_plate=license_plate,
            location=location,
            mechanic_notes=mechanic_notes,
            odometer_meters=odometer_meters,
            resolved_defect_ids=resolved_defect_ids,
            trailer_id=trailer_id,
            vehicle_id=vehicle_id,
            request_options=request_options,
        )
        return _response.data

    async def update_dvir(
        self,
        id: str,
        *,
        author_id: str,
        is_resolved: bool,
        mechanic_notes: typing.Optional[str] = OMIT,
        signed_at_time: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DvirResponse:
        """
        Resolves a given DVIR by marking its `isResolved` field to `true`.

         **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 DVIRs** under the Maintenance 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
        ----------
        id : str
            ID of the DVIR.

        author_id : str
            The user who is resolving the dvir.

        is_resolved : bool
            Resolves the DVIR. Must be `true`.

        mechanic_notes : typing.Optional[str]
            The mechanics notes on the DVIR.

        signed_at_time : typing.Optional[str]
            Time when user signed this DVIR. Defaults to now. UTC timestamp in RFC 3339 format. Example: `2020-01-27T07:06:25Z`.

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

        Returns
        -------
        DvirResponse
            Updated dvir object with ID.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.maintenance.update_dvir(
                id="id",
                author_id="11",
                is_resolved=True,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_dvir(
            id,
            author_id=author_id,
            is_resolved=is_resolved,
            mechanic_notes=mechanic_notes,
            signed_at_time=signed_at_time,
            request_options=request_options,
        )
        return _response.data

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

        Get list of the vehicles with any engine faults or check light 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 DVIRs** under the Maintenance 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
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        InlineResponse2004
            List of vehicles and maintenance information about each.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.maintenance.v_1_get_fleet_maintenance_list()


        asyncio.run(main())
        """
        _response = await self._raw_client.v_1_get_fleet_maintenance_list(request_options=request_options)
        return _response.data
