# 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.coaching_sessions_get_coaching_sessions_response_body import (
    CoachingSessionsGetCoachingSessionsResponseBody,
)
from ..types.driver_coach_assignments_get_driver_coach_assignment_response_body import (
    DriverCoachAssignmentsGetDriverCoachAssignmentResponseBody,
)
from ..types.driver_coach_assignments_put_driver_coach_assignment_response_body import (
    DriverCoachAssignmentsPutDriverCoachAssignmentResponseBody,
)
from .raw_client import AsyncRawCoachingClient, RawCoachingClient


class CoachingClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawCoachingClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawCoachingClient
        """
        return self._raw_client

    def get_driver_coach_assignment(
        self,
        *,
        driver_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        coach_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        include_external_ids: typing.Optional[bool] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DriverCoachAssignmentsGetDriverCoachAssignmentResponseBody:
        """
        This endpoint will return coach assignments for your organization based on the parameters passed in. Results are paginated.

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

        To use this endpoint, select **Read Coaching** under the Coaching 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
        ----------
        driver_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated IDs of the drivers. This can be either a unique Samsara driver ID or an external ID for the driver.

        coach_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated IDs of the coaches.

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

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

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.coaching.get_driver_coach_assignment()
        """
        _response = self._raw_client.get_driver_coach_assignment(
            driver_ids=driver_ids,
            coach_ids=coach_ids,
            include_external_ids=include_external_ids,
            after=after,
            request_options=request_options,
        )
        return _response.data

    def put_driver_coach_assignment(
        self,
        *,
        driver_id: str,
        coach_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DriverCoachAssignmentsPutDriverCoachAssignmentResponseBody:
        """
        This endpoint will update an existing or create a new coach-to-driver assignment for your organization based on the parameters passed in. This endpoint should only be used for existing Coach to Driver assignments. In order to remove a driver-coach-assignment for a given driver, set coachId to null

         <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 Coaching** under the Coaching 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
        ----------
        driver_id : str
            Required string ID of the driver. This is a unique Samsara ID of a driver.

        coach_id : typing.Optional[str]
            Optional string ID of the coach. This is a unique Samsara user ID. If not provided, existing coach assignment will be removed.

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

        Returns
        -------
        DriverCoachAssignmentsPutDriverCoachAssignmentResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.coaching.put_driver_coach_assignment(
            driver_id="driverId",
        )
        """
        _response = self._raw_client.put_driver_coach_assignment(
            driver_id=driver_id, coach_id=coach_id, request_options=request_options
        )
        return _response.data

    def get_coaching_sessions(
        self,
        *,
        start_time: dt.datetime,
        driver_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        coach_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        session_statuses: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        include_coachable_events: typing.Optional[bool] = None,
        end_time: typing.Optional[dt.datetime] = None,
        after: typing.Optional[str] = None,
        include_external_ids: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CoachingSessionsGetCoachingSessionsResponseBody:
        """
        This endpoint will return coaching sessions for your organization based on the time parameters passed in. Results are paginated by sessions. If you include an endTime, the endpoint will return data up until that point. 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 Coaching** under the Coaching 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 : dt.datetime
            Required RFC 3339 timestamp that indicates when to begin receiving data. Value is compared against `updatedAtTime`

        driver_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated driver IDs. If driver ID is present, sessions for the specified driver(s) will be returned.

        coach_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated user IDs. If coach ID is present, sessions for the specified coach(s) will be returned for either assignedCoach or completedCoach. If both driverId(s) and coachId(s) are present, sessions with specified driver(s) and coach(es) will be returned.

        session_statuses : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated statuses. Valid values:  “upcoming”, “completed”, “deleted”.

        include_coachable_events : typing.Optional[bool]
            Optional boolean to control whether behaviors will include coachableEvents in the response. Defaults to false.

        end_time : typing.Optional[dt.datetime]
            Optional RFC 3339 timestamp. If not provided then the endpoint behaves as an unending feed of changes. If endTime is set the same as startTime, the most recent data point before that time will be returned per asset. Value is compared against `updatedAtTime`

        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.

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

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

        Returns
        -------
        CoachingSessionsGetCoachingSessionsResponseBody
            OK response.

        Examples
        --------
        import datetime

        from samsara import Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.coaching.get_coaching_sessions(
            start_time=datetime.datetime.fromisoformat(
                "2024-01-15 09:30:00+00:00",
            ),
        )
        """
        _response = self._raw_client.get_coaching_sessions(
            start_time=start_time,
            driver_ids=driver_ids,
            coach_ids=coach_ids,
            session_statuses=session_statuses,
            include_coachable_events=include_coachable_events,
            end_time=end_time,
            after=after,
            include_external_ids=include_external_ids,
            request_options=request_options,
        )
        return _response.data


class AsyncCoachingClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawCoachingClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawCoachingClient
        """
        return self._raw_client

    async def get_driver_coach_assignment(
        self,
        *,
        driver_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        coach_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        include_external_ids: typing.Optional[bool] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DriverCoachAssignmentsGetDriverCoachAssignmentResponseBody:
        """
        This endpoint will return coach assignments for your organization based on the parameters passed in. Results are paginated.

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

        To use this endpoint, select **Read Coaching** under the Coaching 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
        ----------
        driver_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated IDs of the drivers. This can be either a unique Samsara driver ID or an external ID for the driver.

        coach_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated IDs of the coaches.

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

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

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.coaching.get_driver_coach_assignment()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_driver_coach_assignment(
            driver_ids=driver_ids,
            coach_ids=coach_ids,
            include_external_ids=include_external_ids,
            after=after,
            request_options=request_options,
        )
        return _response.data

    async def put_driver_coach_assignment(
        self,
        *,
        driver_id: str,
        coach_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DriverCoachAssignmentsPutDriverCoachAssignmentResponseBody:
        """
        This endpoint will update an existing or create a new coach-to-driver assignment for your organization based on the parameters passed in. This endpoint should only be used for existing Coach to Driver assignments. In order to remove a driver-coach-assignment for a given driver, set coachId to null

         <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 Coaching** under the Coaching 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
        ----------
        driver_id : str
            Required string ID of the driver. This is a unique Samsara ID of a driver.

        coach_id : typing.Optional[str]
            Optional string ID of the coach. This is a unique Samsara user ID. If not provided, existing coach assignment will be removed.

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

        Returns
        -------
        DriverCoachAssignmentsPutDriverCoachAssignmentResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.coaching.put_driver_coach_assignment(
                driver_id="driverId",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.put_driver_coach_assignment(
            driver_id=driver_id, coach_id=coach_id, request_options=request_options
        )
        return _response.data

    async def get_coaching_sessions(
        self,
        *,
        start_time: dt.datetime,
        driver_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        coach_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        session_statuses: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        include_coachable_events: typing.Optional[bool] = None,
        end_time: typing.Optional[dt.datetime] = None,
        after: typing.Optional[str] = None,
        include_external_ids: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CoachingSessionsGetCoachingSessionsResponseBody:
        """
        This endpoint will return coaching sessions for your organization based on the time parameters passed in. Results are paginated by sessions. If you include an endTime, the endpoint will return data up until that point. 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 Coaching** under the Coaching 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 : dt.datetime
            Required RFC 3339 timestamp that indicates when to begin receiving data. Value is compared against `updatedAtTime`

        driver_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated driver IDs. If driver ID is present, sessions for the specified driver(s) will be returned.

        coach_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated user IDs. If coach ID is present, sessions for the specified coach(s) will be returned for either assignedCoach or completedCoach. If both driverId(s) and coachId(s) are present, sessions with specified driver(s) and coach(es) will be returned.

        session_statuses : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional string of comma separated statuses. Valid values:  “upcoming”, “completed”, “deleted”.

        include_coachable_events : typing.Optional[bool]
            Optional boolean to control whether behaviors will include coachableEvents in the response. Defaults to false.

        end_time : typing.Optional[dt.datetime]
            Optional RFC 3339 timestamp. If not provided then the endpoint behaves as an unending feed of changes. If endTime is set the same as startTime, the most recent data point before that time will be returned per asset. Value is compared against `updatedAtTime`

        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.

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

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

        Returns
        -------
        CoachingSessionsGetCoachingSessionsResponseBody
            OK response.

        Examples
        --------
        import asyncio
        import datetime

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.coaching.get_coaching_sessions(
                start_time=datetime.datetime.fromisoformat(
                    "2024-01-15 09:30:00+00:00",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_coaching_sessions(
            start_time=start_time,
            driver_ids=driver_ids,
            coach_ids=coach_ids,
            session_statuses=session_statuses,
            include_coachable_events=include_coachable_events,
            end_time=end_time,
            after=after,
            include_external_ids=include_external_ids,
            request_options=request_options,
        )
        return _response.data
