# 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.delete_response import DeleteResponse
from ..types.pause_schedule_request import PauseScheduleRequest
from ..types.schedule_list_response import ScheduleListResponse
from ..types.schedule_response import ScheduleResponse
from ..types.unpause_schedule_request import UnpauseScheduleRequest
from .raw_client import AsyncRawSchedulesClient, RawSchedulesClient

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


class SchedulesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawSchedulesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawSchedulesClient
        """
        return self._raw_client

    def agents_schedules_list(
        self,
        agent_id: str,
        *,
        page_size: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ScheduleListResponse:
        """
        List all schedules for an agent.

        Parameters
        ----------
        agent_id : str

        page_size : typing.Optional[int]

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

        Returns
        -------
        ScheduleListResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.schedules.agents_schedules_list(
            agent_id="agent_id",
        )
        """
        _response = self._raw_client.agents_schedules_list(
            agent_id, page_size=page_size, request_options=request_options
        )
        return _response.data

    def agents_schedules_create(
        self,
        agent_id: str,
        *,
        name: str,
        task_queue: str,
        workflow_name: str,
        cron_expression: typing.Optional[str] = OMIT,
        end_at: typing.Optional[dt.datetime] = OMIT,
        execution_timeout_seconds: typing.Optional[int] = OMIT,
        interval_seconds: typing.Optional[int] = OMIT,
        paused: typing.Optional[bool] = OMIT,
        start_at: typing.Optional[dt.datetime] = OMIT,
        workflow_params: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ScheduleResponse:
        """
        Create a new schedule for recurring workflow execution for an agent.

        Parameters
        ----------
        agent_id : str

        name : str
            Human-readable name for the schedule (e.g., 'weekly-profiling'). Will be combined with agent_id to form the full schedule_id.

        task_queue : str
            Temporal task queue where the agent's worker is listening

        workflow_name : str
            Name of the Temporal workflow to execute (e.g., 'sae-orchestrator')

        cron_expression : typing.Optional[str]
            Cron expression for scheduling (e.g., '0 0 * * 0' for weekly on Sunday)

        end_at : typing.Optional[dt.datetime]
            When the schedule should stop being active

        execution_timeout_seconds : typing.Optional[int]
            Maximum time in seconds for each workflow execution

        interval_seconds : typing.Optional[int]
            Alternative to cron - run every N seconds

        paused : typing.Optional[bool]
            Whether to create the schedule in a paused state

        start_at : typing.Optional[dt.datetime]
            When the schedule should start being active

        workflow_params : typing.Optional[typing.Dict[str, typing.Any]]
            Parameters to pass to the workflow

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

        Returns
        -------
        ScheduleResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.schedules.agents_schedules_create(
            agent_id="agent_id",
            name="name",
            task_queue="task_queue",
            workflow_name="workflow_name",
        )
        """
        _response = self._raw_client.agents_schedules_create(
            agent_id,
            name=name,
            task_queue=task_queue,
            workflow_name=workflow_name,
            cron_expression=cron_expression,
            end_at=end_at,
            execution_timeout_seconds=execution_timeout_seconds,
            interval_seconds=interval_seconds,
            paused=paused,
            start_at=start_at,
            workflow_params=workflow_params,
            request_options=request_options,
        )
        return _response.data

    def agents_schedules_retrieve(
        self, agent_id: str, schedule_name: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ScheduleResponse:
        """
        Get details of a schedule by its name.

        Parameters
        ----------
        agent_id : str

        schedule_name : str

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

        Returns
        -------
        ScheduleResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.schedules.agents_schedules_retrieve(
            agent_id="agent_id",
            schedule_name="schedule_name",
        )
        """
        _response = self._raw_client.agents_schedules_retrieve(agent_id, schedule_name, request_options=request_options)
        return _response.data

    def agents_schedules_delete(
        self, agent_id: str, schedule_name: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteResponse:
        """
        Delete a schedule permanently.

        Parameters
        ----------
        agent_id : str

        schedule_name : str

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

        Returns
        -------
        DeleteResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.schedules.agents_schedules_delete(
            agent_id="agent_id",
            schedule_name="schedule_name",
        )
        """
        _response = self._raw_client.agents_schedules_delete(agent_id, schedule_name, request_options=request_options)
        return _response.data

    def agents_schedules_pause(
        self,
        agent_id: str,
        schedule_name: str,
        *,
        request: typing.Optional[PauseScheduleRequest] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ScheduleResponse:
        """
        Pause a schedule to stop it from executing.

        Parameters
        ----------
        agent_id : str

        schedule_name : str

        request : typing.Optional[PauseScheduleRequest]

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

        Returns
        -------
        ScheduleResponse
            Successful Response

        Examples
        --------
        from terminaluse import PauseScheduleRequest, TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.schedules.agents_schedules_pause(
            agent_id="agent_id",
            schedule_name="schedule_name",
            request=PauseScheduleRequest(),
        )
        """
        _response = self._raw_client.agents_schedules_pause(
            agent_id, schedule_name, request=request, request_options=request_options
        )
        return _response.data

    def agents_schedules_trigger(
        self, agent_id: str, schedule_name: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ScheduleResponse:
        """
        Trigger a schedule to run immediately, regardless of its regular schedule.

        Parameters
        ----------
        agent_id : str

        schedule_name : str

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

        Returns
        -------
        ScheduleResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.schedules.agents_schedules_trigger(
            agent_id="agent_id",
            schedule_name="schedule_name",
        )
        """
        _response = self._raw_client.agents_schedules_trigger(agent_id, schedule_name, request_options=request_options)
        return _response.data

    def agents_schedules_unpause(
        self,
        agent_id: str,
        schedule_name: str,
        *,
        request: typing.Optional[UnpauseScheduleRequest] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ScheduleResponse:
        """
        Unpause/resume a schedule to allow it to execute again.

        Parameters
        ----------
        agent_id : str

        schedule_name : str

        request : typing.Optional[UnpauseScheduleRequest]

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

        Returns
        -------
        ScheduleResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase, UnpauseScheduleRequest

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.schedules.agents_schedules_unpause(
            agent_id="agent_id",
            schedule_name="schedule_name",
            request=UnpauseScheduleRequest(),
        )
        """
        _response = self._raw_client.agents_schedules_unpause(
            agent_id, schedule_name, request=request, request_options=request_options
        )
        return _response.data


class AsyncSchedulesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawSchedulesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawSchedulesClient
        """
        return self._raw_client

    async def agents_schedules_list(
        self,
        agent_id: str,
        *,
        page_size: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ScheduleListResponse:
        """
        List all schedules for an agent.

        Parameters
        ----------
        agent_id : str

        page_size : typing.Optional[int]

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

        Returns
        -------
        ScheduleListResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.schedules.agents_schedules_list(
                agent_id="agent_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.agents_schedules_list(
            agent_id, page_size=page_size, request_options=request_options
        )
        return _response.data

    async def agents_schedules_create(
        self,
        agent_id: str,
        *,
        name: str,
        task_queue: str,
        workflow_name: str,
        cron_expression: typing.Optional[str] = OMIT,
        end_at: typing.Optional[dt.datetime] = OMIT,
        execution_timeout_seconds: typing.Optional[int] = OMIT,
        interval_seconds: typing.Optional[int] = OMIT,
        paused: typing.Optional[bool] = OMIT,
        start_at: typing.Optional[dt.datetime] = OMIT,
        workflow_params: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ScheduleResponse:
        """
        Create a new schedule for recurring workflow execution for an agent.

        Parameters
        ----------
        agent_id : str

        name : str
            Human-readable name for the schedule (e.g., 'weekly-profiling'). Will be combined with agent_id to form the full schedule_id.

        task_queue : str
            Temporal task queue where the agent's worker is listening

        workflow_name : str
            Name of the Temporal workflow to execute (e.g., 'sae-orchestrator')

        cron_expression : typing.Optional[str]
            Cron expression for scheduling (e.g., '0 0 * * 0' for weekly on Sunday)

        end_at : typing.Optional[dt.datetime]
            When the schedule should stop being active

        execution_timeout_seconds : typing.Optional[int]
            Maximum time in seconds for each workflow execution

        interval_seconds : typing.Optional[int]
            Alternative to cron - run every N seconds

        paused : typing.Optional[bool]
            Whether to create the schedule in a paused state

        start_at : typing.Optional[dt.datetime]
            When the schedule should start being active

        workflow_params : typing.Optional[typing.Dict[str, typing.Any]]
            Parameters to pass to the workflow

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

        Returns
        -------
        ScheduleResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.schedules.agents_schedules_create(
                agent_id="agent_id",
                name="name",
                task_queue="task_queue",
                workflow_name="workflow_name",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.agents_schedules_create(
            agent_id,
            name=name,
            task_queue=task_queue,
            workflow_name=workflow_name,
            cron_expression=cron_expression,
            end_at=end_at,
            execution_timeout_seconds=execution_timeout_seconds,
            interval_seconds=interval_seconds,
            paused=paused,
            start_at=start_at,
            workflow_params=workflow_params,
            request_options=request_options,
        )
        return _response.data

    async def agents_schedules_retrieve(
        self, agent_id: str, schedule_name: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ScheduleResponse:
        """
        Get details of a schedule by its name.

        Parameters
        ----------
        agent_id : str

        schedule_name : str

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

        Returns
        -------
        ScheduleResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.schedules.agents_schedules_retrieve(
                agent_id="agent_id",
                schedule_name="schedule_name",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.agents_schedules_retrieve(
            agent_id, schedule_name, request_options=request_options
        )
        return _response.data

    async def agents_schedules_delete(
        self, agent_id: str, schedule_name: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteResponse:
        """
        Delete a schedule permanently.

        Parameters
        ----------
        agent_id : str

        schedule_name : str

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

        Returns
        -------
        DeleteResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.schedules.agents_schedules_delete(
                agent_id="agent_id",
                schedule_name="schedule_name",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.agents_schedules_delete(
            agent_id, schedule_name, request_options=request_options
        )
        return _response.data

    async def agents_schedules_pause(
        self,
        agent_id: str,
        schedule_name: str,
        *,
        request: typing.Optional[PauseScheduleRequest] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ScheduleResponse:
        """
        Pause a schedule to stop it from executing.

        Parameters
        ----------
        agent_id : str

        schedule_name : str

        request : typing.Optional[PauseScheduleRequest]

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

        Returns
        -------
        ScheduleResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase, PauseScheduleRequest

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.schedules.agents_schedules_pause(
                agent_id="agent_id",
                schedule_name="schedule_name",
                request=PauseScheduleRequest(),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.agents_schedules_pause(
            agent_id, schedule_name, request=request, request_options=request_options
        )
        return _response.data

    async def agents_schedules_trigger(
        self, agent_id: str, schedule_name: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ScheduleResponse:
        """
        Trigger a schedule to run immediately, regardless of its regular schedule.

        Parameters
        ----------
        agent_id : str

        schedule_name : str

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

        Returns
        -------
        ScheduleResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.schedules.agents_schedules_trigger(
                agent_id="agent_id",
                schedule_name="schedule_name",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.agents_schedules_trigger(
            agent_id, schedule_name, request_options=request_options
        )
        return _response.data

    async def agents_schedules_unpause(
        self,
        agent_id: str,
        schedule_name: str,
        *,
        request: typing.Optional[UnpauseScheduleRequest] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ScheduleResponse:
        """
        Unpause/resume a schedule to allow it to execute again.

        Parameters
        ----------
        agent_id : str

        schedule_name : str

        request : typing.Optional[UnpauseScheduleRequest]

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

        Returns
        -------
        ScheduleResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase, UnpauseScheduleRequest

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.schedules.agents_schedules_unpause(
                agent_id="agent_id",
                schedule_name="schedule_name",
                request=UnpauseScheduleRequest(),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.agents_schedules_unpause(
            agent_id, schedule_name, request=request, request_options=request_options
        )
        return _response.data
