# 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.hub_plans_create_hub_plan_response_body import HubPlansCreateHubPlanResponseBody
from ..types.hub_plans_list_hub_plans_response_body import HubPlansListHubPlansResponseBody
from .raw_client import AsyncRawPlansClient, RawPlansClient

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


class PlansClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawPlansClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawPlansClient
        """
        return self._raw_client

    def create_hub_plan(
        self,
        *,
        hub_id: str,
        name: str,
        shift_start_time: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HubPlansCreateHubPlanResponseBody:
        """
        Create a new plan.

         <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 **Write Routes** under the Driver Workflow 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
        ----------
        hub_id : str
            The ID of the hub the plan belongs to

        name : str
            The name of the plan

        shift_start_time : typing.Optional[dt.datetime]
            The shift start time for the plan in RFC 3339 format. If not provided, defaults to 9:00 AM on the next business day in the hub's timezone.

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

        Returns
        -------
        HubPlansCreateHubPlanResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.plans.create_hub_plan(
            hub_id="550e8400-e29b-41d4-a716-446655440000",
            name="Weekly Plan - Week 15",
        )
        """
        _response = self._raw_client.create_hub_plan(
            hub_id=hub_id, name=name, shift_start_time=shift_start_time, request_options=request_options
        )
        return _response.data

    def list_hub_plans(
        self,
        *,
        hub_id: str,
        plan_ids: typing.Optional[str] = None,
        start_time: typing.Optional[dt.datetime] = None,
        end_time: typing.Optional[dt.datetime] = None,
        after: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HubPlansListHubPlansResponseBody:
        """
        Retrieve all plans for a specific hub.

         <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 Routes** under the Driver Workflow 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
        ----------
        hub_id : str
            The hub identifier

        plan_ids : typing.Optional[str]
            Comma-separated list of plan IDs for filtering.

        start_time : typing.Optional[dt.datetime]
            Time filter of when the plan was updated, in RFC 3339 format

        end_time : typing.Optional[dt.datetime]
            Time filter of when the plan was updated, in RFC 3339 format

        after : typing.Optional[str]
            If specified, should be the endCursor from the previous page of results. When present, this request will return the next page of results that occur immediately after the previous page of results.

        limit : typing.Optional[int]
            Maximum number of objects to return. Default and maximum is 100

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

        Returns
        -------
        HubPlansListHubPlansResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.plans.list_hub_plans(
            hub_id="hubId",
        )
        """
        _response = self._raw_client.list_hub_plans(
            hub_id=hub_id,
            plan_ids=plan_ids,
            start_time=start_time,
            end_time=end_time,
            after=after,
            limit=limit,
            request_options=request_options,
        )
        return _response.data


class AsyncPlansClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawPlansClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawPlansClient
        """
        return self._raw_client

    async def create_hub_plan(
        self,
        *,
        hub_id: str,
        name: str,
        shift_start_time: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HubPlansCreateHubPlanResponseBody:
        """
        Create a new plan.

         <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 **Write Routes** under the Driver Workflow 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
        ----------
        hub_id : str
            The ID of the hub the plan belongs to

        name : str
            The name of the plan

        shift_start_time : typing.Optional[dt.datetime]
            The shift start time for the plan in RFC 3339 format. If not provided, defaults to 9:00 AM on the next business day in the hub's timezone.

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

        Returns
        -------
        HubPlansCreateHubPlanResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.plans.create_hub_plan(
                hub_id="550e8400-e29b-41d4-a716-446655440000",
                name="Weekly Plan - Week 15",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_hub_plan(
            hub_id=hub_id, name=name, shift_start_time=shift_start_time, request_options=request_options
        )
        return _response.data

    async def list_hub_plans(
        self,
        *,
        hub_id: str,
        plan_ids: typing.Optional[str] = None,
        start_time: typing.Optional[dt.datetime] = None,
        end_time: typing.Optional[dt.datetime] = None,
        after: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HubPlansListHubPlansResponseBody:
        """
        Retrieve all plans for a specific hub.

         <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 Routes** under the Driver Workflow 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
        ----------
        hub_id : str
            The hub identifier

        plan_ids : typing.Optional[str]
            Comma-separated list of plan IDs for filtering.

        start_time : typing.Optional[dt.datetime]
            Time filter of when the plan was updated, in RFC 3339 format

        end_time : typing.Optional[dt.datetime]
            Time filter of when the plan was updated, in RFC 3339 format

        after : typing.Optional[str]
            If specified, should be the endCursor from the previous page of results. When present, this request will return the next page of results that occur immediately after the previous page of results.

        limit : typing.Optional[int]
            Maximum number of objects to return. Default and maximum is 100

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

        Returns
        -------
        HubPlansListHubPlansResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.plans.list_hub_plans(
                hub_id="hubId",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list_hub_plans(
            hub_id=hub_id,
            plan_ids=plan_ids,
            start_time=start_time,
            end_time=end_time,
            after=after,
            limit=limit,
            request_options=request_options,
        )
        return _response.data
