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

import typing
from json.decoder import JSONDecodeError

from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.request_options import RequestOptions
from ..core.unchecked_base_model import construct_type
from ..errors.not_found_error import NotFoundError
from ..types.activity_log_response import ActivityLogResponse
from .types.list_activity_logs_request_method import ListActivityLogsRequestMethod


class RawActivityLogsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def list(
        self,
        *,
        end_date: typing.Optional[str] = None,
        method: typing.Optional[ListActivityLogsRequestMethod] = None,
        ordering: typing.Optional[str] = None,
        page: typing.Optional[int] = None,
        page_size: typing.Optional[int] = None,
        project: typing.Optional[int] = None,
        search: typing.Optional[str] = None,
        start_date: typing.Optional[str] = None,
        user: typing.Optional[int] = None,
        workspace: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[typing.List[ActivityLogResponse]]:
        """
        <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 activity logs filtered by workspace, project, user, HTTP method, date range or search query.

        Parameters
        ----------
        end_date : typing.Optional[str]
            End date/time (ISO-8601) for log filtering.

        method : typing.Optional[ListActivityLogsRequestMethod]
            HTTP request method used in the log.

        ordering : typing.Optional[str]
            Which field to use when ordering the results.

        page : typing.Optional[int]
            [or "start"] Current page index.

        page_size : typing.Optional[int]
            [or "length"] Logs per page, use -1 to obtain all logs (might be slow).

        project : typing.Optional[int]
            Project ID to filter logs.

        search : typing.Optional[str]
            Search expression using "AND"/"OR" to filter by request URL.

        start_date : typing.Optional[str]
            Start date/time (ISO-8601) for log filtering.

        user : typing.Optional[int]
            User ID to filter logs.

        workspace : typing.Optional[int]
            Workspace owner ID to filter logs.

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

        Returns
        -------
        HttpResponse[typing.List[ActivityLogResponse]]
            Activity logs
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/activity-logs/",
            method="GET",
            params={
                "end_date": end_date,
                "method": method,
                "ordering": ordering,
                "page": page,
                "page_size": page_size,
                "project": project,
                "search": search,
                "start_date": start_date,
                "user": user,
                "workspace": workspace,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[ActivityLogResponse],
                    construct_type(
                        type_=typing.List[ActivityLogResponse],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        construct_type(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


class AsyncRawActivityLogsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list(
        self,
        *,
        end_date: typing.Optional[str] = None,
        method: typing.Optional[ListActivityLogsRequestMethod] = None,
        ordering: typing.Optional[str] = None,
        page: typing.Optional[int] = None,
        page_size: typing.Optional[int] = None,
        project: typing.Optional[int] = None,
        search: typing.Optional[str] = None,
        start_date: typing.Optional[str] = None,
        user: typing.Optional[int] = None,
        workspace: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[typing.List[ActivityLogResponse]]:
        """
        <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 activity logs filtered by workspace, project, user, HTTP method, date range or search query.

        Parameters
        ----------
        end_date : typing.Optional[str]
            End date/time (ISO-8601) for log filtering.

        method : typing.Optional[ListActivityLogsRequestMethod]
            HTTP request method used in the log.

        ordering : typing.Optional[str]
            Which field to use when ordering the results.

        page : typing.Optional[int]
            [or "start"] Current page index.

        page_size : typing.Optional[int]
            [or "length"] Logs per page, use -1 to obtain all logs (might be slow).

        project : typing.Optional[int]
            Project ID to filter logs.

        search : typing.Optional[str]
            Search expression using "AND"/"OR" to filter by request URL.

        start_date : typing.Optional[str]
            Start date/time (ISO-8601) for log filtering.

        user : typing.Optional[int]
            User ID to filter logs.

        workspace : typing.Optional[int]
            Workspace owner ID to filter logs.

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

        Returns
        -------
        AsyncHttpResponse[typing.List[ActivityLogResponse]]
            Activity logs
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/activity-logs/",
            method="GET",
            params={
                "end_date": end_date,
                "method": method,
                "ordering": ordering,
                "page": page,
                "page_size": page_size,
                "project": project,
                "search": search,
                "start_date": start_date,
                "user": user,
                "workspace": workspace,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[ActivityLogResponse],
                    construct_type(
                        type_=typing.List[ActivityLogResponse],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        construct_type(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
