# 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.issues_get_issues_response_body import IssuesGetIssuesResponseBody
from ..types.issues_get_issues_stream_response_body import IssuesGetIssuesStreamResponseBody
from ..types.issues_patch_issue_response_body import IssuesPatchIssueResponseBody
from ..types.patch_issue_request_body_assigned_to_request_body import PatchIssueRequestBodyAssignedToRequestBody
from .raw_client import AsyncRawIssuesClient, RawIssuesClient
from .types.issues_patch_issue_request_body_status import IssuesPatchIssueRequestBodyStatus

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


class IssuesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawIssuesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawIssuesClient
        """
        return self._raw_client

    def get_issues(
        self,
        *,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        include: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> IssuesGetIssuesResponseBody:
        """
        Returns all issues data for the specified IDs.

         <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 Issues** under the Forms 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]]]
            A comma-separated list containing up to 100 issue IDs to filter on. Can be either a unique Samsara ID or an [external ID](https://developers.samsara.com/docs/external-ids) for the issue.

        include : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            A comma separated list of additional fields to include on requested objects. Valid values: `externalIds`

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

        Returns
        -------
        IssuesGetIssuesResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.issues.get_issues()
        """
        _response = self._raw_client.get_issues(ids=ids, include=include, request_options=request_options)
        return _response.data

    def patch_issue(
        self,
        *,
        id: str,
        assigned_to: typing.Optional[PatchIssueRequestBodyAssignedToRequestBody] = OMIT,
        due_date: typing.Optional[dt.datetime] = OMIT,
        external_ids: typing.Optional[typing.Dict[str, str]] = OMIT,
        status: typing.Optional[IssuesPatchIssueRequestBodyStatus] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> IssuesPatchIssueResponseBody:
        """
        Updates an instance of an issue.

         <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 Issues** under the Forms 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 issue. Can be either a unique Samsara ID or an [external ID](https://developers.samsara.com/docs/external-ids) for the issue.

        assigned_to : typing.Optional[PatchIssueRequestBodyAssignedToRequestBody]

        due_date : typing.Optional[dt.datetime]
            Due date of the issue. UTC timestamp in RFC 3339 format.

        external_ids : typing.Optional[typing.Dict[str, str]]
            A map of external ids

        status : typing.Optional[IssuesPatchIssueRequestBodyStatus]
            Status of the issue.  Valid values: `open`, `inProgress`, `resolved`, `dismissed`

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

        Returns
        -------
        IssuesPatchIssueResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.issues.patch_issue(
            id="9814a1fa-f0c6-408b-bf85-51dc3bc71ac7",
        )
        """
        _response = self._raw_client.patch_issue(
            id=id,
            assigned_to=assigned_to,
            due_date=due_date,
            external_ids=external_ids,
            status=status,
            request_options=request_options,
        )
        return _response.data

    def get_issues_stream(
        self,
        *,
        start_time: str,
        end_time: typing.Optional[str] = None,
        after: typing.Optional[str] = None,
        status: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        asset_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        include: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        assigned_to_route_stop_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> IssuesGetIssuesStreamResponseBody:
        """
        Returns all issues data that has been created or modified for your organization based on the time parameters passed in. Results are paginated and are sorted by last modified date. If you include an endTime, the endpoint will return data up until that point (exclusive). If you don’t include an endTime, you can continue to poll the API real-time with the pagination cursor that gets returned on every call.

         <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 Issues** under the Forms 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. Value is compared against `updatedAtTime`. (Examples: 2019-06-13T19:08:25Z, 2019-06-13T19:08:25.455Z, OR 2015-09-15T14:00:12-04:00).

        end_time : typing.Optional[str]
            An end time in RFC 3339 format. Defaults to now if not provided. Millisecond precision and timezones are supported. Value is compared against `updatedAtTime`. (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.

        status : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            A comma-separated list containing status values to filter issues on. Valid values: `open`, `inProgress`, `resolved`, `dismissed`

        asset_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            A comma-separated list containing up to 50 asset IDs to filter issues on. Issues with untracked assets can also be included by passing the value: 'untracked'.

        include : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            A comma separated list of additional fields to include on requested objects. Valid values: `externalIds`

        assigned_to_route_stop_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            A comma-separated list containing up to 50 route stop IDs to filter data on.

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

        Returns
        -------
        IssuesGetIssuesStreamResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.issues.get_issues_stream(
            start_time="startTime",
        )
        """
        _response = self._raw_client.get_issues_stream(
            start_time=start_time,
            end_time=end_time,
            after=after,
            status=status,
            asset_ids=asset_ids,
            include=include,
            assigned_to_route_stop_ids=assigned_to_route_stop_ids,
            request_options=request_options,
        )
        return _response.data


class AsyncIssuesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawIssuesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawIssuesClient
        """
        return self._raw_client

    async def get_issues(
        self,
        *,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        include: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> IssuesGetIssuesResponseBody:
        """
        Returns all issues data for the specified IDs.

         <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 Issues** under the Forms 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]]]
            A comma-separated list containing up to 100 issue IDs to filter on. Can be either a unique Samsara ID or an [external ID](https://developers.samsara.com/docs/external-ids) for the issue.

        include : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            A comma separated list of additional fields to include on requested objects. Valid values: `externalIds`

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

        Returns
        -------
        IssuesGetIssuesResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.issues.get_issues()


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

    async def patch_issue(
        self,
        *,
        id: str,
        assigned_to: typing.Optional[PatchIssueRequestBodyAssignedToRequestBody] = OMIT,
        due_date: typing.Optional[dt.datetime] = OMIT,
        external_ids: typing.Optional[typing.Dict[str, str]] = OMIT,
        status: typing.Optional[IssuesPatchIssueRequestBodyStatus] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> IssuesPatchIssueResponseBody:
        """
        Updates an instance of an issue.

         <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 Issues** under the Forms 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 issue. Can be either a unique Samsara ID or an [external ID](https://developers.samsara.com/docs/external-ids) for the issue.

        assigned_to : typing.Optional[PatchIssueRequestBodyAssignedToRequestBody]

        due_date : typing.Optional[dt.datetime]
            Due date of the issue. UTC timestamp in RFC 3339 format.

        external_ids : typing.Optional[typing.Dict[str, str]]
            A map of external ids

        status : typing.Optional[IssuesPatchIssueRequestBodyStatus]
            Status of the issue.  Valid values: `open`, `inProgress`, `resolved`, `dismissed`

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

        Returns
        -------
        IssuesPatchIssueResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.issues.patch_issue(
                id="9814a1fa-f0c6-408b-bf85-51dc3bc71ac7",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.patch_issue(
            id=id,
            assigned_to=assigned_to,
            due_date=due_date,
            external_ids=external_ids,
            status=status,
            request_options=request_options,
        )
        return _response.data

    async def get_issues_stream(
        self,
        *,
        start_time: str,
        end_time: typing.Optional[str] = None,
        after: typing.Optional[str] = None,
        status: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        asset_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        include: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        assigned_to_route_stop_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> IssuesGetIssuesStreamResponseBody:
        """
        Returns all issues data that has been created or modified for your organization based on the time parameters passed in. Results are paginated and are sorted by last modified date. If you include an endTime, the endpoint will return data up until that point (exclusive). If you don’t include an endTime, you can continue to poll the API real-time with the pagination cursor that gets returned on every call.

         <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 Issues** under the Forms 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. Value is compared against `updatedAtTime`. (Examples: 2019-06-13T19:08:25Z, 2019-06-13T19:08:25.455Z, OR 2015-09-15T14:00:12-04:00).

        end_time : typing.Optional[str]
            An end time in RFC 3339 format. Defaults to now if not provided. Millisecond precision and timezones are supported. Value is compared against `updatedAtTime`. (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.

        status : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            A comma-separated list containing status values to filter issues on. Valid values: `open`, `inProgress`, `resolved`, `dismissed`

        asset_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            A comma-separated list containing up to 50 asset IDs to filter issues on. Issues with untracked assets can also be included by passing the value: 'untracked'.

        include : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            A comma separated list of additional fields to include on requested objects. Valid values: `externalIds`

        assigned_to_route_stop_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            A comma-separated list containing up to 50 route stop IDs to filter data on.

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

        Returns
        -------
        IssuesGetIssuesStreamResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


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


        asyncio.run(main())
        """
        _response = await self._raw_client.get_issues_stream(
            start_time=start_time,
            end_time=end_time,
            after=after,
            status=status,
            asset_ids=asset_ids,
            include=include,
            assigned_to_route_stop_ids=assigned_to_route_stop_ids,
            request_options=request_options,
        )
        return _response.data
