# 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.training_assignments_get_training_assignments_stream_response_body import (
    TrainingAssignmentsGetTrainingAssignmentsStreamResponseBody,
)
from ..types.training_assignments_patch_training_assignments_response_body import (
    TrainingAssignmentsPatchTrainingAssignmentsResponseBody,
)
from ..types.training_assignments_post_training_assignments_response_body import (
    TrainingAssignmentsPostTrainingAssignmentsResponseBody,
)
from .raw_client import AsyncRawTrainingAssignmentsClient, RawTrainingAssignmentsClient


class TrainingAssignmentsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawTrainingAssignmentsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawTrainingAssignmentsClient
        """
        return self._raw_client

    def post_training_assignments(
        self,
        *,
        course_id: str,
        due_at_time: str,
        learner_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TrainingAssignmentsPostTrainingAssignmentsResponseBody:
        """
        Create training assignments. Existing assignments will remain unchanged.

         <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 **Write Training Assignments** under the Training Assignments category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        course_id : str
            String for the course ID.

        due_at_time : str
            Due date of the training assignment in RFC 3339 format. Millisecond precision and timezones are supported.

        learner_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated learner IDs. If learner ID is present, training assignments for the specified learner(s) will be returned. Max value for this value is 100 objects. Example: `learnerIds=driver-281474,driver-46282156`

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

        Returns
        -------
        TrainingAssignmentsPostTrainingAssignmentsResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.training_assignments.post_training_assignments(
            course_id="courseId",
            due_at_time="dueAtTime",
        )
        """
        _response = self._raw_client.post_training_assignments(
            course_id=course_id, due_at_time=due_at_time, learner_ids=learner_ids, request_options=request_options
        )
        return _response.data

    def delete_training_assignments(
        self,
        *,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        This endpoint supports batch deletion operations. The response does not indicate which specific deletions, if any, have failed. On a successful deletion or partial failure, a ‘204 No Content’ status is returned.

         <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 **Write Training Assignments** under the Training Assignments category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            String of comma separated assignments IDs. Max value for this value is 100 objects. Example: `ids=a4db8702-79d5-4396-a717-e301d52ecc11,c6490f6a-d84e-49b5-b0ad-b6baae304075`

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

        Returns
        -------
        None

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.training_assignments.delete_training_assignments()
        """
        _response = self._raw_client.delete_training_assignments(ids=ids, request_options=request_options)
        return _response.data

    def patch_training_assignments(
        self,
        *,
        due_at_time: str,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TrainingAssignmentsPatchTrainingAssignmentsResponseBody:
        """
        Update training assignments.

         <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 **Write Training Assignments** under the Training Assignments category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        due_at_time : str
            Due date of the training assignment in RFC 3339 format. Millisecond precision and timezones are supported.

        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            String of comma separated assignments IDs. Max value for this value is 100 objects. Example: `ids=a4db8702-79d5-4396-a717-e301d52ecc11,c6490f6a-d84e-49b5-b0ad-b6baae304075`

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

        Returns
        -------
        TrainingAssignmentsPatchTrainingAssignmentsResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.training_assignments.patch_training_assignments(
            due_at_time="dueAtTime",
        )
        """
        _response = self._raw_client.patch_training_assignments(
            due_at_time=due_at_time, ids=ids, request_options=request_options
        )
        return _response.data

    def get_training_assignments_stream(
        self,
        *,
        start_time: str,
        after: typing.Optional[str] = None,
        end_time: typing.Optional[str] = None,
        learner_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        course_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        status: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        is_overdue: typing.Optional[bool] = None,
        category_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TrainingAssignmentsGetTrainingAssignmentsStreamResponseBody:
        """
        Returns all training assignments 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, the API will continue to poll with the pagination cursor that gets returned on every call. The hasNextPage response value will be true if there is no endTime specified and endCursor is nonempty.

         <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 Training Assignments** under the Training Assignments category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        start_time : str
             A start 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).

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

        learner_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated learner IDs. If learner ID is present, training assignments for the specified learner(s) will be returned. Max value for this value is 100 objects. Example: `learnerIds=driver-281474,driver-46282156`

        course_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated course IDs. If course ID is present, training assignments for the specified course ID(s) will be returned. Max value for this value is 100 objects. Defaults to returning all courses. Example: `courseIds=a4db8702-79d5-4396-a717-e301d52ecc11,c6490f6a-d84e-49b5-b0ad-b6baae304075`

        status : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated values. If status is present, training assignments for the specified status(s) will be returned. Valid values: "notStarted", "inProgress", "completed". Defaults to returning all courses.

        is_overdue : typing.Optional[bool]
            Optional boolean value. If present, training assignments for the specified overdue status will be returned. Valid values: true, false. Defaults to returning all assignments.

        category_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated category IDs. If category ID is present, training assignments for the specified category ID(s) will be returned. Max value for this value is 100 objects. Example: `categoryIds=a4db8702-79d5-4396-a717-e301d52ecc11,c6490f6a-d84e-49b5-b0ad-b6baae304075`

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

        Returns
        -------
        TrainingAssignmentsGetTrainingAssignmentsStreamResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.training_assignments.get_training_assignments_stream(
            start_time="startTime",
        )
        """
        _response = self._raw_client.get_training_assignments_stream(
            start_time=start_time,
            after=after,
            end_time=end_time,
            learner_ids=learner_ids,
            course_ids=course_ids,
            status=status,
            is_overdue=is_overdue,
            category_ids=category_ids,
            request_options=request_options,
        )
        return _response.data


class AsyncTrainingAssignmentsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawTrainingAssignmentsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawTrainingAssignmentsClient
        """
        return self._raw_client

    async def post_training_assignments(
        self,
        *,
        course_id: str,
        due_at_time: str,
        learner_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TrainingAssignmentsPostTrainingAssignmentsResponseBody:
        """
        Create training assignments. Existing assignments will remain unchanged.

         <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 **Write Training Assignments** under the Training Assignments category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        course_id : str
            String for the course ID.

        due_at_time : str
            Due date of the training assignment in RFC 3339 format. Millisecond precision and timezones are supported.

        learner_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated learner IDs. If learner ID is present, training assignments for the specified learner(s) will be returned. Max value for this value is 100 objects. Example: `learnerIds=driver-281474,driver-46282156`

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

        Returns
        -------
        TrainingAssignmentsPostTrainingAssignmentsResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.training_assignments.post_training_assignments(
                course_id="courseId",
                due_at_time="dueAtTime",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.post_training_assignments(
            course_id=course_id, due_at_time=due_at_time, learner_ids=learner_ids, request_options=request_options
        )
        return _response.data

    async def delete_training_assignments(
        self,
        *,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        This endpoint supports batch deletion operations. The response does not indicate which specific deletions, if any, have failed. On a successful deletion or partial failure, a ‘204 No Content’ status is returned.

         <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 **Write Training Assignments** under the Training Assignments category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            String of comma separated assignments IDs. Max value for this value is 100 objects. Example: `ids=a4db8702-79d5-4396-a717-e301d52ecc11,c6490f6a-d84e-49b5-b0ad-b6baae304075`

        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.training_assignments.delete_training_assignments()


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

    async def patch_training_assignments(
        self,
        *,
        due_at_time: str,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TrainingAssignmentsPatchTrainingAssignmentsResponseBody:
        """
        Update training assignments.

         <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 **Write Training Assignments** under the Training Assignments category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        due_at_time : str
            Due date of the training assignment in RFC 3339 format. Millisecond precision and timezones are supported.

        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            String of comma separated assignments IDs. Max value for this value is 100 objects. Example: `ids=a4db8702-79d5-4396-a717-e301d52ecc11,c6490f6a-d84e-49b5-b0ad-b6baae304075`

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

        Returns
        -------
        TrainingAssignmentsPatchTrainingAssignmentsResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.training_assignments.patch_training_assignments(
                due_at_time="dueAtTime",
            )


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

    async def get_training_assignments_stream(
        self,
        *,
        start_time: str,
        after: typing.Optional[str] = None,
        end_time: typing.Optional[str] = None,
        learner_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        course_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        status: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        is_overdue: typing.Optional[bool] = None,
        category_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TrainingAssignmentsGetTrainingAssignmentsStreamResponseBody:
        """
        Returns all training assignments 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, the API will continue to poll with the pagination cursor that gets returned on every call. The hasNextPage response value will be true if there is no endTime specified and endCursor is nonempty.

         <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 Training Assignments** under the Training Assignments category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        start_time : str
             A start 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).

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

        learner_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated learner IDs. If learner ID is present, training assignments for the specified learner(s) will be returned. Max value for this value is 100 objects. Example: `learnerIds=driver-281474,driver-46282156`

        course_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated course IDs. If course ID is present, training assignments for the specified course ID(s) will be returned. Max value for this value is 100 objects. Defaults to returning all courses. Example: `courseIds=a4db8702-79d5-4396-a717-e301d52ecc11,c6490f6a-d84e-49b5-b0ad-b6baae304075`

        status : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated values. If status is present, training assignments for the specified status(s) will be returned. Valid values: "notStarted", "inProgress", "completed". Defaults to returning all courses.

        is_overdue : typing.Optional[bool]
            Optional boolean value. If present, training assignments for the specified overdue status will be returned. Valid values: true, false. Defaults to returning all assignments.

        category_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated category IDs. If category ID is present, training assignments for the specified category ID(s) will be returned. Max value for this value is 100 objects. Example: `categoryIds=a4db8702-79d5-4396-a717-e301d52ecc11,c6490f6a-d84e-49b5-b0ad-b6baae304075`

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

        Returns
        -------
        TrainingAssignmentsGetTrainingAssignmentsStreamResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


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


        asyncio.run(main())
        """
        _response = await self._raw_client.get_training_assignments_stream(
            start_time=start_time,
            after=after,
            end_time=end_time,
            learner_ids=learner_ids,
            course_ids=course_ids,
            status=status,
            is_overdue=is_overdue,
            category_ids=category_ids,
            request_options=request_options,
        )
        return _response.data
