# 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.task_assignment import TaskAssignment
from .raw_client import AsyncRawAssignmentsClient, RawAssignmentsClient
from .types.assign_assignments_request_type import AssignAssignmentsRequestType
from .types.bulk_assign_assignments_request_filters import BulkAssignAssignmentsRequestFilters
from .types.bulk_assign_assignments_request_selected_items import BulkAssignAssignmentsRequestSelectedItems
from .types.bulk_assign_assignments_request_type import BulkAssignAssignmentsRequestType
from .types.bulk_assign_assignments_response import BulkAssignAssignmentsResponse
from .types.delete_assignments_request_type import DeleteAssignmentsRequestType
from .types.update_assignments_request_type import UpdateAssignmentsRequestType

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


class AssignmentsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawAssignmentsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawAssignmentsClient
        """
        return self._raw_client

    def bulk_assign(
        self,
        id: int,
        *,
        selected_items: BulkAssignAssignmentsRequestSelectedItems,
        type: BulkAssignAssignmentsRequestType,
        users: typing.Sequence[int],
        filters: typing.Optional[BulkAssignAssignmentsRequestFilters] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> BulkAssignAssignmentsResponse:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Assign multiple users to a collection of tasks within a specific project.

        Parameters
        ----------
        id : int

        selected_items : BulkAssignAssignmentsRequestSelectedItems
            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]}`

        type : BulkAssignAssignmentsRequestType
            Assignment type. Use AN for annotate or RE for review.

        users : typing.Sequence[int]
            List of user IDs to assign

        filters : typing.Optional[BulkAssignAssignmentsRequestFilters]
            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"}]}`

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

        Returns
        -------
        BulkAssignAssignmentsResponse
            Success

        Examples
        --------
        from label_studio_sdk import LabelStudio
        from label_studio_sdk.projects.assignments import (
            BulkAssignAssignmentsRequestSelectedItemsIncluded,
        )

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.projects.assignments.bulk_assign(
            id=1,
            selected_items=BulkAssignAssignmentsRequestSelectedItemsIncluded(
                all_=True,
            ),
            type="AN",
            users=[1],
        )
        """
        _response = self._raw_client.bulk_assign(
            id, selected_items=selected_items, type=type, users=users, filters=filters, request_options=request_options
        )
        return _response.data

    def list(
        self, id: int, task_pk: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[TaskAssignment]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Retrieve a list of tasks and assignees for those tasks for a specific project.

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        task_pk : int
            A unique integer value identifying this task.

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

        Returns
        -------
        typing.List[TaskAssignment]
            List of assignments for the task

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

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.projects.assignments.list(
            id=1,
            task_pk=1,
        )
        """
        _response = self._raw_client.list(id, task_pk, request_options=request_options)
        return _response.data

    def assign(
        self,
        id: int,
        task_pk: int,
        *,
        type: AssignAssignmentsRequestType,
        users: typing.Sequence[int],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TaskAssignment:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Assign a user to a task in a specific project.

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        task_pk : int
            A unique integer value identifying this task.

        type : AssignAssignmentsRequestType
            Assignment type. Use AN for annotate or RE for review.

        users : typing.Sequence[int]
            List of user IDs to assign

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

        Returns
        -------
        TaskAssignment


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

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.projects.assignments.assign(
            id=1,
            task_pk=1,
            type="AN",
            users=[1],
        )
        """
        _response = self._raw_client.assign(id, task_pk, type=type, users=users, request_options=request_options)
        return _response.data

    def delete(
        self,
        id: int,
        task_pk: int,
        *,
        type: typing.Optional[DeleteAssignmentsRequestType] = None,
        users: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Remove assignees for a task within a specific project.

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        task_pk : int
            A unique integer value identifying this task.

        type : typing.Optional[DeleteAssignmentsRequestType]
            Assignment type to delete (optional). If omitted, deletes all assignments for the task.

        users : typing.Optional[str]
            Comma separated list of user IDs to delete, as a string. If omitted, deletes all assignees for the given type.

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

        Returns
        -------
        None

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

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.projects.assignments.delete(
            id=1,
            task_pk=1,
        )
        """
        _response = self._raw_client.delete(id, task_pk, type=type, users=users, request_options=request_options)
        return _response.data

    def update(
        self,
        id: int,
        task_pk: int,
        *,
        type: UpdateAssignmentsRequestType,
        users: typing.Sequence[int],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TaskAssignment:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Update the assignee for a task in a specific project.

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        task_pk : int
            A unique integer value identifying this task.

        type : UpdateAssignmentsRequestType
            Assignment type. Use AN for annotate or RE for review.

        users : typing.Sequence[int]
            List of user IDs to assign

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

        Returns
        -------
        TaskAssignment


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

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.projects.assignments.update(
            id=1,
            task_pk=1,
            type="AN",
            users=[1],
        )
        """
        _response = self._raw_client.update(id, task_pk, type=type, users=users, request_options=request_options)
        return _response.data


class AsyncAssignmentsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawAssignmentsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawAssignmentsClient
        """
        return self._raw_client

    async def bulk_assign(
        self,
        id: int,
        *,
        selected_items: BulkAssignAssignmentsRequestSelectedItems,
        type: BulkAssignAssignmentsRequestType,
        users: typing.Sequence[int],
        filters: typing.Optional[BulkAssignAssignmentsRequestFilters] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> BulkAssignAssignmentsResponse:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Assign multiple users to a collection of tasks within a specific project.

        Parameters
        ----------
        id : int

        selected_items : BulkAssignAssignmentsRequestSelectedItems
            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]}`

        type : BulkAssignAssignmentsRequestType
            Assignment type. Use AN for annotate or RE for review.

        users : typing.Sequence[int]
            List of user IDs to assign

        filters : typing.Optional[BulkAssignAssignmentsRequestFilters]
            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"}]}`

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

        Returns
        -------
        BulkAssignAssignmentsResponse
            Success

        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio
        from label_studio_sdk.projects.assignments import (
            BulkAssignAssignmentsRequestSelectedItemsIncluded,
        )

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.projects.assignments.bulk_assign(
                id=1,
                selected_items=BulkAssignAssignmentsRequestSelectedItemsIncluded(
                    all_=True,
                ),
                type="AN",
                users=[1],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.bulk_assign(
            id, selected_items=selected_items, type=type, users=users, filters=filters, request_options=request_options
        )
        return _response.data

    async def list(
        self, id: int, task_pk: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[TaskAssignment]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Retrieve a list of tasks and assignees for those tasks for a specific project.

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        task_pk : int
            A unique integer value identifying this task.

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

        Returns
        -------
        typing.List[TaskAssignment]
            List of assignments for the task

        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.projects.assignments.list(
                id=1,
                task_pk=1,
            )


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

    async def assign(
        self,
        id: int,
        task_pk: int,
        *,
        type: AssignAssignmentsRequestType,
        users: typing.Sequence[int],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TaskAssignment:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Assign a user to a task in a specific project.

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        task_pk : int
            A unique integer value identifying this task.

        type : AssignAssignmentsRequestType
            Assignment type. Use AN for annotate or RE for review.

        users : typing.Sequence[int]
            List of user IDs to assign

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

        Returns
        -------
        TaskAssignment


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.projects.assignments.assign(
                id=1,
                task_pk=1,
                type="AN",
                users=[1],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.assign(id, task_pk, type=type, users=users, request_options=request_options)
        return _response.data

    async def delete(
        self,
        id: int,
        task_pk: int,
        *,
        type: typing.Optional[DeleteAssignmentsRequestType] = None,
        users: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Remove assignees for a task within a specific project.

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        task_pk : int
            A unique integer value identifying this task.

        type : typing.Optional[DeleteAssignmentsRequestType]
            Assignment type to delete (optional). If omitted, deletes all assignments for the task.

        users : typing.Optional[str]
            Comma separated list of user IDs to delete, as a string. If omitted, deletes all assignees for the given type.

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.projects.assignments.delete(
                id=1,
                task_pk=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete(id, task_pk, type=type, users=users, request_options=request_options)
        return _response.data

    async def update(
        self,
        id: int,
        task_pk: int,
        *,
        type: UpdateAssignmentsRequestType,
        users: typing.Sequence[int],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TaskAssignment:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Update the assignee for a task in a specific project.

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        task_pk : int
            A unique integer value identifying this task.

        type : UpdateAssignmentsRequestType
            Assignment type. Use AN for annotate or RE for review.

        users : typing.Sequence[int]
            List of user IDs to assign

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

        Returns
        -------
        TaskAssignment


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.projects.assignments.update(
                id=1,
                task_pk=1,
                type="AN",
                users=[1],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(id, task_pk, type=type, users=users, request_options=request_options)
        return _response.data
