# 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.action_type import ActionType
from ..types.delete_trigger_response import DeleteTriggerResponse
from ..types.execute_trigger_response import ExecuteTriggerResponse
from ..types.list_triggers_response import ListTriggersResponse
from ..types.src_app_http_routes_trigger_create_trigger_response import SrcAppHttpRoutesTriggerCreateTriggerResponse
from ..types.update_cron_auth_response import UpdateCronAuthResponse
from ..types.update_trigger_response import UpdateTriggerResponse
from .raw_client import AsyncRawTriggersClient, RawTriggersClient
from .types.triggers_create_request import TriggersCreateRequest
from .types.triggers_execute_slack_response import TriggersExecuteSlackResponse
from .types.triggers_update_request import TriggersUpdateRequest

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


class TriggersClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawTriggersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawTriggersClient
        """
        return self._raw_client

    def list(
        self,
        *,
        action_type: typing.Optional[ActionType] = None,
        workflow_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListTriggersResponse:
        """
        All apis and effects are injected into every endpoint
        via request.context. The request_context() utility can be used
        to get Intellisense type-completion

        Parameters
        ----------
        action_type : typing.Optional[ActionType]
            Filter by action type

        workflow_id : typing.Optional[str]
            Filter by workflow ID

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

        Returns
        -------
        ListTriggersResponse
            Successful Response

        Examples
        --------
        from scoutos import Scout

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.triggers.list(
            action_type="workflow.execute",
            workflow_id="workflow_id",
        )
        """
        _response = self._raw_client.list(
            action_type=action_type, workflow_id=workflow_id, request_options=request_options
        )
        return _response.data

    def create(
        self, *, request: TriggersCreateRequest, request_options: typing.Optional[RequestOptions] = None
    ) -> SrcAppHttpRoutesTriggerCreateTriggerResponse:
        """
        Parameters
        ----------
        request : TriggersCreateRequest

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

        Returns
        -------
        SrcAppHttpRoutesTriggerCreateTriggerResponse
            Successful Response

        Examples
        --------
        from scoutos import Scout, SlackTriggerConfigInput, SourceSync

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.triggers.create(
            request=SlackTriggerConfigInput(
                action=SourceSync(
                    sync_id="sync_id",
                ),
            ),
        )
        """
        _response = self._raw_client.create(request=request, request_options=request_options)
        return _response.data

    def update(
        self,
        trigger_id: str,
        *,
        request: TriggersUpdateRequest,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateTriggerResponse:
        """
        Parameters
        ----------
        trigger_id : str

        request : TriggersUpdateRequest

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

        Returns
        -------
        UpdateTriggerResponse
            Successful Response

        Examples
        --------
        from scoutos import Scout, SlackTriggerConfigInput, SourceSync

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.triggers.update(
            trigger_id="trigger_id",
            request=SlackTriggerConfigInput(
                action=SourceSync(
                    sync_id="sync_id",
                ),
            ),
        )
        """
        _response = self._raw_client.update(trigger_id, request=request, request_options=request_options)
        return _response.data

    def delete(
        self, trigger_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteTriggerResponse:
        """
        Parameters
        ----------
        trigger_id : str

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

        Returns
        -------
        DeleteTriggerResponse
            Successful Response

        Examples
        --------
        from scoutos import Scout

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.triggers.delete(
            trigger_id="trigger_id",
        )
        """
        _response = self._raw_client.delete(trigger_id, request_options=request_options)
        return _response.data

    def execute_slack(self, *, request_options: typing.Optional[RequestOptions] = None) -> TriggersExecuteSlackResponse:
        """
        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        TriggersExecuteSlackResponse
            Successful Response

        Examples
        --------
        from scoutos import Scout

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.triggers.execute_slack()
        """
        _response = self._raw_client.execute_slack(request_options=request_options)
        return _response.data

    def execute_cron(self, *, request_options: typing.Optional[RequestOptions] = None) -> ExecuteTriggerResponse:
        """
        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ExecuteTriggerResponse
            Successful Response

        Examples
        --------
        from scoutos import Scout

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.triggers.execute_cron()
        """
        _response = self._raw_client.execute_cron(request_options=request_options)
        return _response.data

    def update_cron_auth_headers(
        self,
        *,
        dry_run: typing.Optional[bool] = None,
        test_org_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateCronAuthResponse:
        """
        Update Cloud Scheduler job Authorization headers for organizations.
        Lists all Cloud Scheduler jobs and updates those matching the trigger pattern.

        Args:
            dry_run: If True, only shows what would be updated without making changes
            test_org_id: If provided, only processes jobs for this specific organization ID

        Only accessible to Scout internal organizations for security.

        Parameters
        ----------
        dry_run : typing.Optional[bool]

        test_org_id : typing.Optional[str]

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

        Returns
        -------
        UpdateCronAuthResponse
            Successful Response

        Examples
        --------
        from scoutos import Scout

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.triggers.update_cron_auth_headers(
            dry_run=True,
            test_org_id="test_org_id",
        )
        """
        _response = self._raw_client.update_cron_auth_headers(
            dry_run=dry_run, test_org_id=test_org_id, request_options=request_options
        )
        return _response.data


class AsyncTriggersClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawTriggersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawTriggersClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        action_type: typing.Optional[ActionType] = None,
        workflow_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListTriggersResponse:
        """
        All apis and effects are injected into every endpoint
        via request.context. The request_context() utility can be used
        to get Intellisense type-completion

        Parameters
        ----------
        action_type : typing.Optional[ActionType]
            Filter by action type

        workflow_id : typing.Optional[str]
            Filter by workflow ID

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

        Returns
        -------
        ListTriggersResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.triggers.list(
                action_type="workflow.execute",
                workflow_id="workflow_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            action_type=action_type, workflow_id=workflow_id, request_options=request_options
        )
        return _response.data

    async def create(
        self, *, request: TriggersCreateRequest, request_options: typing.Optional[RequestOptions] = None
    ) -> SrcAppHttpRoutesTriggerCreateTriggerResponse:
        """
        Parameters
        ----------
        request : TriggersCreateRequest

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

        Returns
        -------
        SrcAppHttpRoutesTriggerCreateTriggerResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout, SlackTriggerConfigInput, SourceSync

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.triggers.create(
                request=SlackTriggerConfigInput(
                    action=SourceSync(
                        sync_id="sync_id",
                    ),
                ),
            )


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

    async def update(
        self,
        trigger_id: str,
        *,
        request: TriggersUpdateRequest,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateTriggerResponse:
        """
        Parameters
        ----------
        trigger_id : str

        request : TriggersUpdateRequest

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

        Returns
        -------
        UpdateTriggerResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout, SlackTriggerConfigInput, SourceSync

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.triggers.update(
                trigger_id="trigger_id",
                request=SlackTriggerConfigInput(
                    action=SourceSync(
                        sync_id="sync_id",
                    ),
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(trigger_id, request=request, request_options=request_options)
        return _response.data

    async def delete(
        self, trigger_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteTriggerResponse:
        """
        Parameters
        ----------
        trigger_id : str

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

        Returns
        -------
        DeleteTriggerResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.triggers.delete(
                trigger_id="trigger_id",
            )


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

    async def execute_slack(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> TriggersExecuteSlackResponse:
        """
        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        TriggersExecuteSlackResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.triggers.execute_slack()


        asyncio.run(main())
        """
        _response = await self._raw_client.execute_slack(request_options=request_options)
        return _response.data

    async def execute_cron(self, *, request_options: typing.Optional[RequestOptions] = None) -> ExecuteTriggerResponse:
        """
        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ExecuteTriggerResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.triggers.execute_cron()


        asyncio.run(main())
        """
        _response = await self._raw_client.execute_cron(request_options=request_options)
        return _response.data

    async def update_cron_auth_headers(
        self,
        *,
        dry_run: typing.Optional[bool] = None,
        test_org_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateCronAuthResponse:
        """
        Update Cloud Scheduler job Authorization headers for organizations.
        Lists all Cloud Scheduler jobs and updates those matching the trigger pattern.

        Args:
            dry_run: If True, only shows what would be updated without making changes
            test_org_id: If provided, only processes jobs for this specific organization ID

        Only accessible to Scout internal organizations for security.

        Parameters
        ----------
        dry_run : typing.Optional[bool]

        test_org_id : typing.Optional[str]

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

        Returns
        -------
        UpdateCronAuthResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.triggers.update_cron_auth_headers(
                dry_run=True,
                test_org_id="test_org_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_cron_auth_headers(
            dry_run=dry_run, test_org_id=test_org_id, request_options=request_options
        )
        return _response.data
