# 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 .raw_client import AsyncRawActionsClient, RawActionsClient
from .types.create_actions_request_filters import CreateActionsRequestFilters
from .types.create_actions_request_id import CreateActionsRequestId
from .types.create_actions_request_ordering_item import CreateActionsRequestOrderingItem
from .types.create_actions_request_selected_items import CreateActionsRequestSelectedItems
from .types.list_actions_response_item import ListActionsResponseItem

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


class ActionsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawActionsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawActionsClient
        """
        return self._raw_client

    def list(
        self, *, project: int, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[ListActionsResponseItem]:
        """
        Retrieve all the registered actions with descriptions that data manager can use.

        Parameters
        ----------
        project : int
            Project ID

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

        Returns
        -------
        typing.List[ListActionsResponseItem]
            Actions retrieved successfully

        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.actions.list(
            project=1,
        )
        """
        _response = self._raw_client.list(project=project, request_options=request_options)
        return _response.data

    def create(
        self,
        *,
        id: CreateActionsRequestId,
        project: int,
        view: typing.Optional[int] = None,
        filters: typing.Optional[CreateActionsRequestFilters] = OMIT,
        ordering: typing.Optional[typing.Sequence[CreateActionsRequestOrderingItem]] = OMIT,
        selected_items: typing.Optional[CreateActionsRequestSelectedItems] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Perform a Data Manager action with the selected tasks and filters. Note: More complex actions require additional parameters in the request body. Call `GET api/actions?project=<id>` to explore them. <br>Example: `GET api/actions?id=delete_tasks&project=1`

        Parameters
        ----------
        id : CreateActionsRequestId
            Action name ID, see the full list of actions in the `GET api/actions` request

        project : int
            Project ID

        view : typing.Optional[int]
            View ID (optional, it has higher priority than filters, selectedItems and ordering from the request body payload)

        filters : typing.Optional[CreateActionsRequestFilters]
            Filters to apply on tasks. You can use [the helper class `Filters` from this page](https://labelstud.io/sdk/data_manager.html) to create Data Manager Filters.<br>Example: `{"conjunction": "or", "items": [{"filter": "filter:tasks:completed_at", "operator": "greater", "type": "Datetime", "value": "2021-01-01T00:00:00.000Z"}]}`

        ordering : typing.Optional[typing.Sequence[CreateActionsRequestOrderingItem]]
            List of fields to order by. Fields are similar to filters but without the `filter:` prefix. To reverse the order, add a minus sign before the field name, e.g. `-tasks:created_at`.

        selected_items : typing.Optional[CreateActionsRequestSelectedItems]
            Task selection by IDs. If filters are applied, the selection will be applied to the filtered tasks.If "all" is `false`, `"included"` must be used. If "all" is `true`, `"excluded"` must be used.<br>Examples: `{"all": false, "included": [1, 2, 3]}` or `{"all": true, "excluded": [4, 5]}`

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

        Returns
        -------
        None

        Examples
        --------
        from label_studio_sdk import LabelStudio
        from label_studio_sdk.actions import (
            CreateActionsRequestFilters,
            CreateActionsRequestFiltersItemsItem,
            CreateActionsRequestSelectedItemsExcluded,
        )

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.actions.create(
            id="delete_annotators",
            project=1,
            filters=CreateActionsRequestFilters(
                conjunction="or",
                items=[
                    CreateActionsRequestFiltersItemsItem(
                        filter="filter:tasks:id",
                        operator="greater",
                        type="Number",
                        value=123,
                    )
                ],
            ),
            ordering=["tasks:total_annotations"],
            selected_items=CreateActionsRequestSelectedItemsExcluded(
                all_=True,
                excluded=[124, 125, 126],
            ),
        )
        """
        _response = self._raw_client.create(
            id=id,
            project=project,
            view=view,
            filters=filters,
            ordering=ordering,
            selected_items=selected_items,
            request_options=request_options,
        )
        return _response.data


class AsyncActionsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawActionsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawActionsClient
        """
        return self._raw_client

    async def list(
        self, *, project: int, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[ListActionsResponseItem]:
        """
        Retrieve all the registered actions with descriptions that data manager can use.

        Parameters
        ----------
        project : int
            Project ID

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

        Returns
        -------
        typing.List[ListActionsResponseItem]
            Actions retrieved successfully

        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.actions.list(
                project=1,
            )


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

    async def create(
        self,
        *,
        id: CreateActionsRequestId,
        project: int,
        view: typing.Optional[int] = None,
        filters: typing.Optional[CreateActionsRequestFilters] = OMIT,
        ordering: typing.Optional[typing.Sequence[CreateActionsRequestOrderingItem]] = OMIT,
        selected_items: typing.Optional[CreateActionsRequestSelectedItems] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Perform a Data Manager action with the selected tasks and filters. Note: More complex actions require additional parameters in the request body. Call `GET api/actions?project=<id>` to explore them. <br>Example: `GET api/actions?id=delete_tasks&project=1`

        Parameters
        ----------
        id : CreateActionsRequestId
            Action name ID, see the full list of actions in the `GET api/actions` request

        project : int
            Project ID

        view : typing.Optional[int]
            View ID (optional, it has higher priority than filters, selectedItems and ordering from the request body payload)

        filters : typing.Optional[CreateActionsRequestFilters]
            Filters to apply on tasks. You can use [the helper class `Filters` from this page](https://labelstud.io/sdk/data_manager.html) to create Data Manager Filters.<br>Example: `{"conjunction": "or", "items": [{"filter": "filter:tasks:completed_at", "operator": "greater", "type": "Datetime", "value": "2021-01-01T00:00:00.000Z"}]}`

        ordering : typing.Optional[typing.Sequence[CreateActionsRequestOrderingItem]]
            List of fields to order by. Fields are similar to filters but without the `filter:` prefix. To reverse the order, add a minus sign before the field name, e.g. `-tasks:created_at`.

        selected_items : typing.Optional[CreateActionsRequestSelectedItems]
            Task selection by IDs. If filters are applied, the selection will be applied to the filtered tasks.If "all" is `false`, `"included"` must be used. If "all" is `true`, `"excluded"` must be used.<br>Examples: `{"all": false, "included": [1, 2, 3]}` or `{"all": true, "excluded": [4, 5]}`

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio
        from label_studio_sdk.actions import (
            CreateActionsRequestFilters,
            CreateActionsRequestFiltersItemsItem,
            CreateActionsRequestSelectedItemsExcluded,
        )

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.actions.create(
                id="delete_annotators",
                project=1,
                filters=CreateActionsRequestFilters(
                    conjunction="or",
                    items=[
                        CreateActionsRequestFiltersItemsItem(
                            filter="filter:tasks:id",
                            operator="greater",
                            type="Number",
                            value=123,
                        )
                    ],
                ),
                ordering=["tasks:total_annotations"],
                selected_items=CreateActionsRequestSelectedItemsExcluded(
                    all_=True,
                    excluded=[124, 125, 126],
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            id=id,
            project=project,
            view=view,
            filters=filters,
            ordering=ordering,
            selected_items=selected_items,
            request_options=request_options,
        )
        return _response.data
