# This file was auto-generated by Fern from our API Definition.

from ...core.client_wrapper import SyncClientWrapper
from .bulk.client import BulkClient
import typing
from ...core.request_options import RequestOptions
from ...types.lse_user import LseUser
from ...core.jsonable_encoder import jsonable_encoder
from ...core.unchecked_base_model import construct_type
from json.decoder import JSONDecodeError
from ...core.api_error import ApiError
from ...core.client_wrapper import AsyncClientWrapper
from .bulk.client import AsyncBulkClient


class MembersClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper
        self.bulk = BulkClient(client_wrapper=self._client_wrapper)

    def get(
        self, id: int, *, user_ids: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[LseUser]:
        """
        Retrieve the members for a specific project. Optionally filter by user IDs (comma-separated).

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

        user_ids : typing.Optional[str]
            Comma-separated list of user IDs to include. Example: user_ids=1,2,3

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

        Returns
        -------
        typing.List[LseUser]
            List of users with membership information

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

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.projects.members.get(
            id=1,
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/members/",
            method="GET",
            params={
                "user_ids": user_ids,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    typing.List[LseUser],
                    construct_type(
                        type_=typing.List[LseUser],  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)


class AsyncMembersClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper
        self.bulk = AsyncBulkClient(client_wrapper=self._client_wrapper)

    async def get(
        self, id: int, *, user_ids: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[LseUser]:
        """
        Retrieve the members for a specific project. Optionally filter by user IDs (comma-separated).

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

        user_ids : typing.Optional[str]
            Comma-separated list of user IDs to include. Example: user_ids=1,2,3

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

        Returns
        -------
        typing.List[LseUser]
            List of users with membership information

        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.projects.members.get(
                id=1,
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/members/",
            method="GET",
            params={
                "user_ids": user_ids,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    typing.List[LseUser],
                    construct_type(
                        type_=typing.List[LseUser],  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)
