# This file was auto-generated by Fern from our API Definition.

import datetime as dt
import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.invoice_scan_file_request_body import InvoiceScanFileRequestBody
from ..types.service_task_instance_input_object_request_body import ServiceTaskInstanceInputObjectRequestBody
from ..types.work_order_discount_object_request_body import WorkOrderDiscountObjectRequestBody
from ..types.work_order_item_object_request_body import WorkOrderItemObjectRequestBody
from ..types.work_order_tax_create_object_request_body import WorkOrderTaxCreateObjectRequestBody
from ..types.work_order_tax_object_request_body import WorkOrderTaxObjectRequestBody
from ..types.work_orders_get_service_tasks_response_body import WorkOrdersGetServiceTasksResponseBody
from ..types.work_orders_get_work_orders_response_body import WorkOrdersGetWorkOrdersResponseBody
from ..types.work_orders_patch_work_orders_response_body import WorkOrdersPatchWorkOrdersResponseBody
from ..types.work_orders_post_invoice_scan_response_body import WorkOrdersPostInvoiceScanResponseBody
from ..types.work_orders_post_work_orders_response_body import WorkOrdersPostWorkOrdersResponseBody
from ..types.work_orders_stream_work_orders_response_body import WorkOrdersStreamWorkOrdersResponseBody
from .raw_client import AsyncRawWorkOrdersClient, RawWorkOrdersClient
from .types.stream_work_orders_request_work_order_statuses_item import StreamWorkOrdersRequestWorkOrderStatusesItem
from .types.work_orders_patch_work_orders_request_body_priority import WorkOrdersPatchWorkOrdersRequestBodyPriority
from .types.work_orders_patch_work_orders_request_body_status import WorkOrdersPatchWorkOrdersRequestBodyStatus
from .types.work_orders_post_work_orders_request_body_priority import WorkOrdersPostWorkOrdersRequestBodyPriority

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


class WorkOrdersClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawWorkOrdersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawWorkOrdersClient
        """
        return self._raw_client

    def post_invoice_scan(
        self,
        *,
        file: InvoiceScanFileRequestBody,
        asset_id: typing.Optional[str] = OMIT,
        work_order_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WorkOrdersPostInvoiceScanResponseBody:
        """
        Process an invoice scan to create or update a work order with AI-extracted data. Accepts base64 encoded invoice files (PDF, JPEG, PNG) up to 10MB.

         <b>Rate limit:</b> 100 requests/min (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Write Work Orders** under the Work Orders 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
        ----------
        file : InvoiceScanFileRequestBody

        asset_id : typing.Optional[str]
            Asset ID to create a new work order for the invoice. Provide either workOrderId OR assetId, but not both. If assetId is provided, a new work order will be created for that asset. If workOrderId is provided instead, the invoice will be attached to the existing work order.

        work_order_id : typing.Optional[str]
            Work order ID to attach the invoice to an existing work order. Provide either workOrderId OR assetId, but not both. If workOrderId is provided, the invoice will be attached to the existing work order. If assetId is provided instead, a new work order will be created for that asset.

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

        Returns
        -------
        WorkOrdersPostInvoiceScanResponseBody
            OK response.

        Examples
        --------
        from samsara import InvoiceScanFileRequestBody, Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.work_orders.post_invoice_scan(
            file=InvoiceScanFileRequestBody(
                base_64_content="JVBERi0xLjQKJeLjz9MKMyAwIG9iago8P...",
                content_type="application/pdf",
            ),
        )
        """
        _response = self._raw_client.post_invoice_scan(
            file=file, asset_id=asset_id, work_order_id=work_order_id, request_options=request_options
        )
        return _response.data

    def get_service_tasks(
        self,
        *,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        include_archived: typing.Optional[bool] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WorkOrdersGetServiceTasksResponseBody:
        """
        Gets service tasks.

         <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 Work Orders** under the Work Orders 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
        ----------
        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Filter by the IDs. If not provided, won't filter by id.

        include_archived : typing.Optional[bool]
            Include archived service task definitions.

        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.

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

        Returns
        -------
        WorkOrdersGetServiceTasksResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.work_orders.get_service_tasks()
        """
        _response = self._raw_client.get_service_tasks(
            ids=ids, include_archived=include_archived, after=after, request_options=request_options
        )
        return _response.data

    def get_work_orders(
        self,
        *,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WorkOrdersGetWorkOrdersResponseBody:
        """
        Gets work orders.

         <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 Work Orders** under the Work Orders 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
        ----------
        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Filter by the IDs. Up to 100 ids. Returns all if no ids are provided.

        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.

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

        Returns
        -------
        WorkOrdersGetWorkOrdersResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.work_orders.get_work_orders()
        """
        _response = self._raw_client.get_work_orders(ids=ids, after=after, request_options=request_options)
        return _response.data

    def post_work_orders(
        self,
        *,
        asset_id: str,
        assigned_user_id: typing.Optional[str] = OMIT,
        category: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        discount: typing.Optional[WorkOrderDiscountObjectRequestBody] = OMIT,
        due_at_time: typing.Optional[dt.datetime] = OMIT,
        engine_hours: typing.Optional[int] = OMIT,
        invoice_number: typing.Optional[str] = OMIT,
        items: typing.Optional[typing.Sequence[WorkOrderItemObjectRequestBody]] = OMIT,
        odometer_meters: typing.Optional[int] = OMIT,
        po_number: typing.Optional[str] = OMIT,
        priority: typing.Optional[WorkOrdersPostWorkOrdersRequestBodyPriority] = OMIT,
        service_task_instances: typing.Optional[typing.Sequence[ServiceTaskInstanceInputObjectRequestBody]] = OMIT,
        tax: typing.Optional[WorkOrderTaxCreateObjectRequestBody] = OMIT,
        vendor_uuid: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WorkOrdersPostWorkOrdersResponseBody:
        """
        Creates a work order.

         <b>Rate limit:</b> 100 requests/min (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Write Work Orders** under the Work Orders 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
        ----------
        asset_id : str
            The ID of the asset.

        assigned_user_id : typing.Optional[str]
            The ID of the assigned mechanic.

        category : typing.Optional[str]
            The category of the work order

        description : typing.Optional[str]
            A description of what needs to be fixed.

        discount : typing.Optional[WorkOrderDiscountObjectRequestBody]

        due_at_time : typing.Optional[dt.datetime]
            The due date of the work order in RFC 3339 format.

        engine_hours : typing.Optional[int]
            The engine hours at the time of the work order. Will default to current asset reading if unset.

        invoice_number : typing.Optional[str]
            The invoice number for the work order.

        items : typing.Optional[typing.Sequence[WorkOrderItemObjectRequestBody]]
            Items related to the work order.

        odometer_meters : typing.Optional[int]
            The odometer reading at the time of the work order. Will default to current asset reading if unset.

        po_number : typing.Optional[str]
            The purchase order number for the work order.

        priority : typing.Optional[WorkOrdersPostWorkOrdersRequestBodyPriority]
            The priority of the work order  Valid values: `High`, `Low`, `Medium`, `Urgent`

        service_task_instances : typing.Optional[typing.Sequence[ServiceTaskInstanceInputObjectRequestBody]]
            Service Tasks for the work order.

        tax : typing.Optional[WorkOrderTaxCreateObjectRequestBody]

        vendor_uuid : typing.Optional[str]
            The vendor UUID for the work order.

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

        Returns
        -------
        WorkOrdersPostWorkOrdersResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.work_orders.post_work_orders(
            asset_id="12443",
        )
        """
        _response = self._raw_client.post_work_orders(
            asset_id=asset_id,
            assigned_user_id=assigned_user_id,
            category=category,
            description=description,
            discount=discount,
            due_at_time=due_at_time,
            engine_hours=engine_hours,
            invoice_number=invoice_number,
            items=items,
            odometer_meters=odometer_meters,
            po_number=po_number,
            priority=priority,
            service_task_instances=service_task_instances,
            tax=tax,
            vendor_uuid=vendor_uuid,
            request_options=request_options,
        )
        return _response.data

    def delete_work_orders(self, *, id: str, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Deletes a work order.

         <b>Rate limit:</b> 100 requests/min (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Write Work Orders** under the Work Orders 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 work order.

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

        Returns
        -------
        None

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.work_orders.delete_work_orders(
            id="id",
        )
        """
        _response = self._raw_client.delete_work_orders(id=id, request_options=request_options)
        return _response.data

    def patch_work_orders(
        self,
        *,
        id: str,
        assigned_user_id: typing.Optional[str] = OMIT,
        category: typing.Optional[str] = OMIT,
        closing_notes: typing.Optional[str] = OMIT,
        completed_at_time: typing.Optional[dt.datetime] = OMIT,
        description: typing.Optional[str] = OMIT,
        discount: typing.Optional[WorkOrderDiscountObjectRequestBody] = OMIT,
        due_at_time: typing.Optional[dt.datetime] = OMIT,
        engine_hours: typing.Optional[int] = OMIT,
        invoice_number: typing.Optional[str] = OMIT,
        items: typing.Optional[typing.Sequence[WorkOrderItemObjectRequestBody]] = OMIT,
        odometer_meters: typing.Optional[int] = OMIT,
        po_number: typing.Optional[str] = OMIT,
        priority: typing.Optional[WorkOrdersPatchWorkOrdersRequestBodyPriority] = OMIT,
        service_task_instances: typing.Optional[typing.Sequence[ServiceTaskInstanceInputObjectRequestBody]] = OMIT,
        status: typing.Optional[WorkOrdersPatchWorkOrdersRequestBodyStatus] = OMIT,
        tax: typing.Optional[WorkOrderTaxObjectRequestBody] = OMIT,
        vendor_uuid: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WorkOrdersPatchWorkOrdersResponseBody:
        """
        Updates a work order.

         <b>Rate limit:</b> 100 requests/min (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Write Work Orders** under the Work Orders 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 work order.

        assigned_user_id : typing.Optional[str]
            The ID of the assigned mechanic.

        category : typing.Optional[str]
            The category of the work order

        closing_notes : typing.Optional[str]
            Notes on the work order.

        completed_at_time : typing.Optional[dt.datetime]
            The time the work order was completed in RFC 3339 format. Is automatically set when the status changes and this field is not provided.

        description : typing.Optional[str]
            A description of what needs to be fixed.

        discount : typing.Optional[WorkOrderDiscountObjectRequestBody]

        due_at_time : typing.Optional[dt.datetime]
            The due date of the work order in RFC 3339 format.

        engine_hours : typing.Optional[int]
            The engine hours at the time of the work order. Will default to current asset reading if unset.

        invoice_number : typing.Optional[str]
            The invoice number for the work order.

        items : typing.Optional[typing.Sequence[WorkOrderItemObjectRequestBody]]
            Items related to the work order.

        odometer_meters : typing.Optional[int]
            The odometer reading at the time of the work order. Will default to current asset reading if unset.

        po_number : typing.Optional[str]
            The purchase order number for the work order.

        priority : typing.Optional[WorkOrdersPatchWorkOrdersRequestBodyPriority]
            The priority of the work order  Valid values: `High`, `Low`, `Medium`, `Urgent`

        service_task_instances : typing.Optional[typing.Sequence[ServiceTaskInstanceInputObjectRequestBody]]
            Service Tasks for the work order.

        status : typing.Optional[WorkOrdersPatchWorkOrdersRequestBodyStatus]
            The status of the work order  Valid values: `Assigned`, `Cancelled`, `Closed`, `Completed`, `In Progress`, `On Hold`, `Open`, `Pending Approval`, `Pending Parts`

        tax : typing.Optional[WorkOrderTaxObjectRequestBody]

        vendor_uuid : typing.Optional[str]
            The vendor UUID for the work order.

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

        Returns
        -------
        WorkOrdersPatchWorkOrdersResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.work_orders.patch_work_orders(
            id="5",
        )
        """
        _response = self._raw_client.patch_work_orders(
            id=id,
            assigned_user_id=assigned_user_id,
            category=category,
            closing_notes=closing_notes,
            completed_at_time=completed_at_time,
            description=description,
            discount=discount,
            due_at_time=due_at_time,
            engine_hours=engine_hours,
            invoice_number=invoice_number,
            items=items,
            odometer_meters=odometer_meters,
            po_number=po_number,
            priority=priority,
            service_task_instances=service_task_instances,
            status=status,
            tax=tax,
            vendor_uuid=vendor_uuid,
            request_options=request_options,
        )
        return _response.data

    def stream_work_orders(
        self,
        *,
        start_time: str,
        after: typing.Optional[str] = None,
        end_time: typing.Optional[str] = None,
        work_order_statuses: typing.Optional[
            typing.Union[
                StreamWorkOrdersRequestWorkOrderStatusesItem,
                typing.Sequence[StreamWorkOrdersRequestWorkOrderStatusesItem],
            ]
        ] = None,
        asset_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        assigned_user_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WorkOrdersStreamWorkOrdersResponseBody:
        """
        Stream work orders.

         <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 Work Orders** under the Work Orders 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
            A start time 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).

        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.

        end_time : typing.Optional[str]
             An end time in RFC 3339 format. Defaults to now if not provided. 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).

        work_order_statuses : typing.Optional[typing.Union[StreamWorkOrdersRequestWorkOrderStatusesItem, typing.Sequence[StreamWorkOrdersRequestWorkOrderStatusesItem]]]
            Work Order status filter.

        asset_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Work Order asset id filter. Up to 50 ids.

        assigned_user_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Work Order assigned user id filter. Up to 50 ids.

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

        Returns
        -------
        WorkOrdersStreamWorkOrdersResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.work_orders.stream_work_orders(
            start_time="startTime",
        )
        """
        _response = self._raw_client.stream_work_orders(
            start_time=start_time,
            after=after,
            end_time=end_time,
            work_order_statuses=work_order_statuses,
            asset_ids=asset_ids,
            assigned_user_ids=assigned_user_ids,
            request_options=request_options,
        )
        return _response.data


class AsyncWorkOrdersClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawWorkOrdersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawWorkOrdersClient
        """
        return self._raw_client

    async def post_invoice_scan(
        self,
        *,
        file: InvoiceScanFileRequestBody,
        asset_id: typing.Optional[str] = OMIT,
        work_order_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WorkOrdersPostInvoiceScanResponseBody:
        """
        Process an invoice scan to create or update a work order with AI-extracted data. Accepts base64 encoded invoice files (PDF, JPEG, PNG) up to 10MB.

         <b>Rate limit:</b> 100 requests/min (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Write Work Orders** under the Work Orders 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
        ----------
        file : InvoiceScanFileRequestBody

        asset_id : typing.Optional[str]
            Asset ID to create a new work order for the invoice. Provide either workOrderId OR assetId, but not both. If assetId is provided, a new work order will be created for that asset. If workOrderId is provided instead, the invoice will be attached to the existing work order.

        work_order_id : typing.Optional[str]
            Work order ID to attach the invoice to an existing work order. Provide either workOrderId OR assetId, but not both. If workOrderId is provided, the invoice will be attached to the existing work order. If assetId is provided instead, a new work order will be created for that asset.

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

        Returns
        -------
        WorkOrdersPostInvoiceScanResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara, InvoiceScanFileRequestBody

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.work_orders.post_invoice_scan(
                file=InvoiceScanFileRequestBody(
                    base_64_content="JVBERi0xLjQKJeLjz9MKMyAwIG9iago8P...",
                    content_type="application/pdf",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.post_invoice_scan(
            file=file, asset_id=asset_id, work_order_id=work_order_id, request_options=request_options
        )
        return _response.data

    async def get_service_tasks(
        self,
        *,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        include_archived: typing.Optional[bool] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WorkOrdersGetServiceTasksResponseBody:
        """
        Gets service tasks.

         <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 Work Orders** under the Work Orders 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
        ----------
        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Filter by the IDs. If not provided, won't filter by id.

        include_archived : typing.Optional[bool]
            Include archived service task definitions.

        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.

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

        Returns
        -------
        WorkOrdersGetServiceTasksResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.work_orders.get_service_tasks()


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

    async def get_work_orders(
        self,
        *,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WorkOrdersGetWorkOrdersResponseBody:
        """
        Gets work orders.

         <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 Work Orders** under the Work Orders 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
        ----------
        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Filter by the IDs. Up to 100 ids. Returns all if no ids are provided.

        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.

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

        Returns
        -------
        WorkOrdersGetWorkOrdersResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.work_orders.get_work_orders()


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

    async def post_work_orders(
        self,
        *,
        asset_id: str,
        assigned_user_id: typing.Optional[str] = OMIT,
        category: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        discount: typing.Optional[WorkOrderDiscountObjectRequestBody] = OMIT,
        due_at_time: typing.Optional[dt.datetime] = OMIT,
        engine_hours: typing.Optional[int] = OMIT,
        invoice_number: typing.Optional[str] = OMIT,
        items: typing.Optional[typing.Sequence[WorkOrderItemObjectRequestBody]] = OMIT,
        odometer_meters: typing.Optional[int] = OMIT,
        po_number: typing.Optional[str] = OMIT,
        priority: typing.Optional[WorkOrdersPostWorkOrdersRequestBodyPriority] = OMIT,
        service_task_instances: typing.Optional[typing.Sequence[ServiceTaskInstanceInputObjectRequestBody]] = OMIT,
        tax: typing.Optional[WorkOrderTaxCreateObjectRequestBody] = OMIT,
        vendor_uuid: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WorkOrdersPostWorkOrdersResponseBody:
        """
        Creates a work order.

         <b>Rate limit:</b> 100 requests/min (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Write Work Orders** under the Work Orders 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
        ----------
        asset_id : str
            The ID of the asset.

        assigned_user_id : typing.Optional[str]
            The ID of the assigned mechanic.

        category : typing.Optional[str]
            The category of the work order

        description : typing.Optional[str]
            A description of what needs to be fixed.

        discount : typing.Optional[WorkOrderDiscountObjectRequestBody]

        due_at_time : typing.Optional[dt.datetime]
            The due date of the work order in RFC 3339 format.

        engine_hours : typing.Optional[int]
            The engine hours at the time of the work order. Will default to current asset reading if unset.

        invoice_number : typing.Optional[str]
            The invoice number for the work order.

        items : typing.Optional[typing.Sequence[WorkOrderItemObjectRequestBody]]
            Items related to the work order.

        odometer_meters : typing.Optional[int]
            The odometer reading at the time of the work order. Will default to current asset reading if unset.

        po_number : typing.Optional[str]
            The purchase order number for the work order.

        priority : typing.Optional[WorkOrdersPostWorkOrdersRequestBodyPriority]
            The priority of the work order  Valid values: `High`, `Low`, `Medium`, `Urgent`

        service_task_instances : typing.Optional[typing.Sequence[ServiceTaskInstanceInputObjectRequestBody]]
            Service Tasks for the work order.

        tax : typing.Optional[WorkOrderTaxCreateObjectRequestBody]

        vendor_uuid : typing.Optional[str]
            The vendor UUID for the work order.

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

        Returns
        -------
        WorkOrdersPostWorkOrdersResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.work_orders.post_work_orders(
                asset_id="12443",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.post_work_orders(
            asset_id=asset_id,
            assigned_user_id=assigned_user_id,
            category=category,
            description=description,
            discount=discount,
            due_at_time=due_at_time,
            engine_hours=engine_hours,
            invoice_number=invoice_number,
            items=items,
            odometer_meters=odometer_meters,
            po_number=po_number,
            priority=priority,
            service_task_instances=service_task_instances,
            tax=tax,
            vendor_uuid=vendor_uuid,
            request_options=request_options,
        )
        return _response.data

    async def delete_work_orders(self, *, id: str, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Deletes a work order.

         <b>Rate limit:</b> 100 requests/min (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Write Work Orders** under the Work Orders 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 work order.

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


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


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

    async def patch_work_orders(
        self,
        *,
        id: str,
        assigned_user_id: typing.Optional[str] = OMIT,
        category: typing.Optional[str] = OMIT,
        closing_notes: typing.Optional[str] = OMIT,
        completed_at_time: typing.Optional[dt.datetime] = OMIT,
        description: typing.Optional[str] = OMIT,
        discount: typing.Optional[WorkOrderDiscountObjectRequestBody] = OMIT,
        due_at_time: typing.Optional[dt.datetime] = OMIT,
        engine_hours: typing.Optional[int] = OMIT,
        invoice_number: typing.Optional[str] = OMIT,
        items: typing.Optional[typing.Sequence[WorkOrderItemObjectRequestBody]] = OMIT,
        odometer_meters: typing.Optional[int] = OMIT,
        po_number: typing.Optional[str] = OMIT,
        priority: typing.Optional[WorkOrdersPatchWorkOrdersRequestBodyPriority] = OMIT,
        service_task_instances: typing.Optional[typing.Sequence[ServiceTaskInstanceInputObjectRequestBody]] = OMIT,
        status: typing.Optional[WorkOrdersPatchWorkOrdersRequestBodyStatus] = OMIT,
        tax: typing.Optional[WorkOrderTaxObjectRequestBody] = OMIT,
        vendor_uuid: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WorkOrdersPatchWorkOrdersResponseBody:
        """
        Updates a work order.

         <b>Rate limit:</b> 100 requests/min (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Write Work Orders** under the Work Orders 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 work order.

        assigned_user_id : typing.Optional[str]
            The ID of the assigned mechanic.

        category : typing.Optional[str]
            The category of the work order

        closing_notes : typing.Optional[str]
            Notes on the work order.

        completed_at_time : typing.Optional[dt.datetime]
            The time the work order was completed in RFC 3339 format. Is automatically set when the status changes and this field is not provided.

        description : typing.Optional[str]
            A description of what needs to be fixed.

        discount : typing.Optional[WorkOrderDiscountObjectRequestBody]

        due_at_time : typing.Optional[dt.datetime]
            The due date of the work order in RFC 3339 format.

        engine_hours : typing.Optional[int]
            The engine hours at the time of the work order. Will default to current asset reading if unset.

        invoice_number : typing.Optional[str]
            The invoice number for the work order.

        items : typing.Optional[typing.Sequence[WorkOrderItemObjectRequestBody]]
            Items related to the work order.

        odometer_meters : typing.Optional[int]
            The odometer reading at the time of the work order. Will default to current asset reading if unset.

        po_number : typing.Optional[str]
            The purchase order number for the work order.

        priority : typing.Optional[WorkOrdersPatchWorkOrdersRequestBodyPriority]
            The priority of the work order  Valid values: `High`, `Low`, `Medium`, `Urgent`

        service_task_instances : typing.Optional[typing.Sequence[ServiceTaskInstanceInputObjectRequestBody]]
            Service Tasks for the work order.

        status : typing.Optional[WorkOrdersPatchWorkOrdersRequestBodyStatus]
            The status of the work order  Valid values: `Assigned`, `Cancelled`, `Closed`, `Completed`, `In Progress`, `On Hold`, `Open`, `Pending Approval`, `Pending Parts`

        tax : typing.Optional[WorkOrderTaxObjectRequestBody]

        vendor_uuid : typing.Optional[str]
            The vendor UUID for the work order.

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

        Returns
        -------
        WorkOrdersPatchWorkOrdersResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.work_orders.patch_work_orders(
                id="5",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.patch_work_orders(
            id=id,
            assigned_user_id=assigned_user_id,
            category=category,
            closing_notes=closing_notes,
            completed_at_time=completed_at_time,
            description=description,
            discount=discount,
            due_at_time=due_at_time,
            engine_hours=engine_hours,
            invoice_number=invoice_number,
            items=items,
            odometer_meters=odometer_meters,
            po_number=po_number,
            priority=priority,
            service_task_instances=service_task_instances,
            status=status,
            tax=tax,
            vendor_uuid=vendor_uuid,
            request_options=request_options,
        )
        return _response.data

    async def stream_work_orders(
        self,
        *,
        start_time: str,
        after: typing.Optional[str] = None,
        end_time: typing.Optional[str] = None,
        work_order_statuses: typing.Optional[
            typing.Union[
                StreamWorkOrdersRequestWorkOrderStatusesItem,
                typing.Sequence[StreamWorkOrdersRequestWorkOrderStatusesItem],
            ]
        ] = None,
        asset_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        assigned_user_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WorkOrdersStreamWorkOrdersResponseBody:
        """
        Stream work orders.

         <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 Work Orders** under the Work Orders 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
            A start time 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).

        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.

        end_time : typing.Optional[str]
             An end time in RFC 3339 format. Defaults to now if not provided. 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).

        work_order_statuses : typing.Optional[typing.Union[StreamWorkOrdersRequestWorkOrderStatusesItem, typing.Sequence[StreamWorkOrdersRequestWorkOrderStatusesItem]]]
            Work Order status filter.

        asset_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Work Order asset id filter. Up to 50 ids.

        assigned_user_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Work Order assigned user id filter. Up to 50 ids.

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

        Returns
        -------
        WorkOrdersStreamWorkOrdersResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


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


        asyncio.run(main())
        """
        _response = await self._raw_client.stream_work_orders(
            start_time=start_time,
            after=after,
            end_time=end_time,
            work_order_statuses=work_order_statuses,
            asset_ids=asset_ids,
            assigned_user_ids=assigned_user_ids,
            request_options=request_options,
        )
        return _response.data
