"""
RCABench API

RCABench - A comprehensive root cause analysis benchmarking platform for microservices

The version of the OpenAPI document: 1.1.51
Contact: team@rcabench.com
Generated by OpenAPI Generator (https://rcabench.openapi-generator.tech)

Do not edit the class manually.
"""  # noqa: E501

from typing import Annotated, Any

from pydantic import Field, StrictBool, StrictFloat, StrictInt, StrictStr, validate_call

from rcabench.openapi.api_client import ApiClient, RequestSerialized
from rcabench.openapi.api_response import ApiResponse
from rcabench.openapi.models.generic_response_list_task_resp import GenericResponseListTaskResp
from rcabench.openapi.models.generic_response_task_detail_resp import GenericResponseTaskDetailResp
from rcabench.openapi.models.status_type import StatusType
from rcabench.openapi.models.task_state import TaskState
from rcabench.openapi.rest import RESTResponse, RESTResponseType


class TasksApi:
    """NOTE: This class is auto generated by OpenAPI Generator
    Ref: https://rcabench.openapi-generator.tech

    Do not edit the class manually.
    """

    def __init__(self, api_client=None) -> None:
        if api_client is None:
            api_client = ApiClient.get_default()
        self.api_client = api_client

    @validate_call
    def get_task_by_id(
        self,
        task_id: Annotated[StrictStr, Field(description="Task ID")],
        _request_timeout: None
        | Annotated[StrictFloat, Field(gt=0)]
        | tuple[Annotated[StrictStr, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]] = None,
        _request_auth: dict[StrictStr, Any] | None = None,
        _content_type: StrictStr | None = None,
        _headers: dict[StrictStr, Any] | None = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> GenericResponseTaskDetailResp:
        """Get task by ID

        Get detailed information about a specific task

        :param task_id: Task ID (required)
        :type task_id: str
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :type _request_timeout: int, tuple(int, int), optional
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the
                              authentication in the spec for a single request.
        :type _request_auth: dict, optional
        :param _content_type: force content-type for the request.
        :type _content_type: str, Optional
        :param _headers: set to override the headers for a single
                         request; this effectively ignores the headers
                         in the spec for a single request.
        :type _headers: dict, optional
        :param _host_index: set to override the host_index for a single
                            request; this effectively ignores the host_index
                            in the spec for a single request.
        :type _host_index: int, optional
        :return: Returns the result object.
        """  # noqa: E501

        _param = self._get_task_by_id_serialize(
            task_id=task_id,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index,
        )

        _response_types_map: dict[str, str | None] = {
            "200": "GenericResponseTaskDetailResp",
            "400": "GenericResponseAny",
            "401": "GenericResponseAny",
            "403": "GenericResponseAny",
            "404": "GenericResponseAny",
            "500": "GenericResponseAny",
        }
        response_data = self.api_client.call_api(*_param, _request_timeout=_request_timeout)

        assert response_data is not None and isinstance(response_data, RESTResponse), (
            "Response data must be of type RESTResponse"
        )
        response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        ).data  # type: ignore

    @validate_call
    def get_task_by_id_with_http_info(
        self,
        task_id: Annotated[StrictStr, Field(description="Task ID")],
        _request_timeout: None
        | Annotated[StrictFloat, Field(gt=0)]
        | tuple[Annotated[StrictStr, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]] = None,
        _request_auth: dict[StrictStr, Any] | None = None,
        _content_type: StrictStr | None = None,
        _headers: dict[StrictStr, Any] | None = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> ApiResponse[GenericResponseTaskDetailResp]:
        """Get task by ID

        Get detailed information about a specific task

        :param task_id: Task ID (required)
        :type task_id: str
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :type _request_timeout: int, tuple(int, int), optional
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the
                              authentication in the spec for a single request.
        :type _request_auth: dict, optional
        :param _content_type: force content-type for the request.
        :type _content_type: str, Optional
        :param _headers: set to override the headers for a single
                         request; this effectively ignores the headers
                         in the spec for a single request.
        :type _headers: dict, optional
        :param _host_index: set to override the host_index for a single
                            request; this effectively ignores the host_index
                            in the spec for a single request.
        :type _host_index: int, optional
        :return: Returns the result object.
        """  # noqa: E501

        _param = self._get_task_by_id_serialize(
            task_id=task_id,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index,
        )

        _response_types_map: dict[str, str | None] = {
            "200": "GenericResponseTaskDetailResp",
            "400": "GenericResponseAny",
            "401": "GenericResponseAny",
            "403": "GenericResponseAny",
            "404": "GenericResponseAny",
            "500": "GenericResponseAny",
        }
        response_data = self.api_client.call_api(*_param, _request_timeout=_request_timeout)

        assert response_data is not None and isinstance(response_data, RESTResponse), (
            "Response data must be of type RESTResponse"
        )
        response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        )  # type: ignore

    @validate_call
    def get_task_by_id_without_preload_content(
        self,
        task_id: Annotated[StrictStr, Field(description="Task ID")],
        _request_timeout: None
        | Annotated[StrictFloat, Field(gt=0)]
        | tuple[Annotated[StrictStr, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]] = None,
        _request_auth: dict[StrictStr, Any] | None = None,
        _content_type: StrictStr | None = None,
        _headers: dict[StrictStr, Any] | None = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> RESTResponseType:
        """Get task by ID

        Get detailed information about a specific task

        :param task_id: Task ID (required)
        :type task_id: str
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :type _request_timeout: int, tuple(int, int), optional
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the
                              authentication in the spec for a single request.
        :type _request_auth: dict, optional
        :param _content_type: force content-type for the request.
        :type _content_type: str, Optional
        :param _headers: set to override the headers for a single
                         request; this effectively ignores the headers
                         in the spec for a single request.
        :type _headers: dict, optional
        :param _host_index: set to override the host_index for a single
                            request; this effectively ignores the host_index
                            in the spec for a single request.
        :type _host_index: int, optional
        :return: Returns the result object.
        """  # noqa: E501

        _param = self._get_task_by_id_serialize(
            task_id=task_id,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index,
        )

        _response_types_map: dict[str, str | None] = {
            "200": "GenericResponseTaskDetailResp",
            "400": "GenericResponseAny",
            "401": "GenericResponseAny",
            "403": "GenericResponseAny",
            "404": "GenericResponseAny",
            "500": "GenericResponseAny",
        }
        response_data = self.api_client.call_api(*_param, _request_timeout=_request_timeout)

        assert response_data is not None and isinstance(response_data, RESTResponse), (
            "Response data must be of type RESTResponse"
        )
        return response_data.response

    def _get_task_by_id_serialize(
        self,
        task_id,
        _request_auth,
        _content_type,
        _headers,
        _host_index,
    ) -> RequestSerialized:
        _host = None

        _collection_formats: dict[str, str] = {}

        _path_params: dict[str, str] = {}
        _query_params: list[tuple[str, str]] = []
        _header_params: dict[str, str | None] = _headers or {}
        _form_params: list[tuple[str, str]] = []
        _files: dict[str, str | bytes | list[str] | list[bytes] | list[tuple[str, bytes]]] = {}
        _body_params: bytes | None = None

        # process the path parameters
        if task_id is not None:
            _path_params["task_id"] = task_id
        # process the query parameters
        # process the header parameters
        # process the form parameters
        # process the body parameter

        # set the HTTP header `Accept`
        if "Accept" not in _header_params:
            _header_params["Accept"] = self.api_client.select_header_accept(["application/json"])

        # authentication setting
        _auth_settings: list[str] = ["BearerAuth"]

        return self.api_client.param_serialize(
            method="GET",
            resource_path="/api/v2/tasks/{task_id}",
            path_params=_path_params,
            query_params=_query_params,
            header_params=_header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            auth_settings=_auth_settings,
            collection_formats=_collection_formats,
            _host=_host,
            _request_auth=_request_auth,
        )

    @validate_call
    def list_tasks(
        self,
        page: Annotated[StrictInt | None, Field(description="Page number")] = None,
        size: Annotated[StrictInt | None, Field(description="Page size")] = None,
        task_type: Annotated[StrictInt | None, Field(description="Filter by task type")] = None,
        immediate: Annotated[StrictBool | None, Field(description="Filter by immediate execution")] = None,
        trace_id: Annotated[StrictStr | None, Field(description="Filter by trace ID (uuid format)")] = None,
        group_id: Annotated[StrictStr | None, Field(description="Filter by group ID (uuid format)")] = None,
        project_id: Annotated[StrictInt | None, Field(description="Filter by project ID")] = None,
        state: Annotated[TaskState | None, Field(description="Filter by state")] = None,
        status: Annotated[StatusType | None, Field(description="Filter by status")] = None,
        _request_timeout: None
        | Annotated[StrictFloat, Field(gt=0)]
        | tuple[Annotated[StrictStr, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]] = None,
        _request_auth: dict[StrictStr, Any] | None = None,
        _content_type: StrictStr | None = None,
        _headers: dict[StrictStr, Any] | None = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> GenericResponseListTaskResp:
        """List tasks

        Get a simple list of tasks with basic filtering via query parameters

        :param page: Page number
        :type page: int
        :param size: Page size
        :type size: int
        :param task_type: Filter by task type
        :type task_type: int
        :param immediate: Filter by immediate execution
        :type immediate: bool
        :param trace_id: Filter by trace ID (uuid format)
        :type trace_id: str
        :param group_id: Filter by group ID (uuid format)
        :type group_id: str
        :param project_id: Filter by project ID
        :type project_id: int
        :param state: Filter by state
        :type state: TaskState
        :param status: Filter by status
        :type status: StatusType
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :type _request_timeout: int, tuple(int, int), optional
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the
                              authentication in the spec for a single request.
        :type _request_auth: dict, optional
        :param _content_type: force content-type for the request.
        :type _content_type: str, Optional
        :param _headers: set to override the headers for a single
                         request; this effectively ignores the headers
                         in the spec for a single request.
        :type _headers: dict, optional
        :param _host_index: set to override the host_index for a single
                            request; this effectively ignores the host_index
                            in the spec for a single request.
        :type _host_index: int, optional
        :return: Returns the result object.
        """  # noqa: E501

        _param = self._list_tasks_serialize(
            page=page,
            size=size,
            task_type=task_type,
            immediate=immediate,
            trace_id=trace_id,
            group_id=group_id,
            project_id=project_id,
            state=state,
            status=status,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index,
        )

        _response_types_map: dict[str, str | None] = {
            "200": "GenericResponseListTaskResp",
            "400": "GenericResponseAny",
            "401": "GenericResponseAny",
            "403": "GenericResponseAny",
            "500": "GenericResponseAny",
        }
        response_data = self.api_client.call_api(*_param, _request_timeout=_request_timeout)

        assert response_data is not None and isinstance(response_data, RESTResponse), (
            "Response data must be of type RESTResponse"
        )
        response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        ).data  # type: ignore

    @validate_call
    def list_tasks_with_http_info(
        self,
        page: Annotated[StrictInt | None, Field(description="Page number")] = None,
        size: Annotated[StrictInt | None, Field(description="Page size")] = None,
        task_type: Annotated[StrictInt | None, Field(description="Filter by task type")] = None,
        immediate: Annotated[StrictBool | None, Field(description="Filter by immediate execution")] = None,
        trace_id: Annotated[StrictStr | None, Field(description="Filter by trace ID (uuid format)")] = None,
        group_id: Annotated[StrictStr | None, Field(description="Filter by group ID (uuid format)")] = None,
        project_id: Annotated[StrictInt | None, Field(description="Filter by project ID")] = None,
        state: Annotated[TaskState | None, Field(description="Filter by state")] = None,
        status: Annotated[StatusType | None, Field(description="Filter by status")] = None,
        _request_timeout: None
        | Annotated[StrictFloat, Field(gt=0)]
        | tuple[Annotated[StrictStr, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]] = None,
        _request_auth: dict[StrictStr, Any] | None = None,
        _content_type: StrictStr | None = None,
        _headers: dict[StrictStr, Any] | None = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> ApiResponse[GenericResponseListTaskResp]:
        """List tasks

        Get a simple list of tasks with basic filtering via query parameters

        :param page: Page number
        :type page: int
        :param size: Page size
        :type size: int
        :param task_type: Filter by task type
        :type task_type: int
        :param immediate: Filter by immediate execution
        :type immediate: bool
        :param trace_id: Filter by trace ID (uuid format)
        :type trace_id: str
        :param group_id: Filter by group ID (uuid format)
        :type group_id: str
        :param project_id: Filter by project ID
        :type project_id: int
        :param state: Filter by state
        :type state: TaskState
        :param status: Filter by status
        :type status: StatusType
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :type _request_timeout: int, tuple(int, int), optional
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the
                              authentication in the spec for a single request.
        :type _request_auth: dict, optional
        :param _content_type: force content-type for the request.
        :type _content_type: str, Optional
        :param _headers: set to override the headers for a single
                         request; this effectively ignores the headers
                         in the spec for a single request.
        :type _headers: dict, optional
        :param _host_index: set to override the host_index for a single
                            request; this effectively ignores the host_index
                            in the spec for a single request.
        :type _host_index: int, optional
        :return: Returns the result object.
        """  # noqa: E501

        _param = self._list_tasks_serialize(
            page=page,
            size=size,
            task_type=task_type,
            immediate=immediate,
            trace_id=trace_id,
            group_id=group_id,
            project_id=project_id,
            state=state,
            status=status,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index,
        )

        _response_types_map: dict[str, str | None] = {
            "200": "GenericResponseListTaskResp",
            "400": "GenericResponseAny",
            "401": "GenericResponseAny",
            "403": "GenericResponseAny",
            "500": "GenericResponseAny",
        }
        response_data = self.api_client.call_api(*_param, _request_timeout=_request_timeout)

        assert response_data is not None and isinstance(response_data, RESTResponse), (
            "Response data must be of type RESTResponse"
        )
        response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        )  # type: ignore

    @validate_call
    def list_tasks_without_preload_content(
        self,
        page: Annotated[StrictInt | None, Field(description="Page number")] = None,
        size: Annotated[StrictInt | None, Field(description="Page size")] = None,
        task_type: Annotated[StrictInt | None, Field(description="Filter by task type")] = None,
        immediate: Annotated[StrictBool | None, Field(description="Filter by immediate execution")] = None,
        trace_id: Annotated[StrictStr | None, Field(description="Filter by trace ID (uuid format)")] = None,
        group_id: Annotated[StrictStr | None, Field(description="Filter by group ID (uuid format)")] = None,
        project_id: Annotated[StrictInt | None, Field(description="Filter by project ID")] = None,
        state: Annotated[TaskState | None, Field(description="Filter by state")] = None,
        status: Annotated[StatusType | None, Field(description="Filter by status")] = None,
        _request_timeout: None
        | Annotated[StrictFloat, Field(gt=0)]
        | tuple[Annotated[StrictStr, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]] = None,
        _request_auth: dict[StrictStr, Any] | None = None,
        _content_type: StrictStr | None = None,
        _headers: dict[StrictStr, Any] | None = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> RESTResponseType:
        """List tasks

        Get a simple list of tasks with basic filtering via query parameters

        :param page: Page number
        :type page: int
        :param size: Page size
        :type size: int
        :param task_type: Filter by task type
        :type task_type: int
        :param immediate: Filter by immediate execution
        :type immediate: bool
        :param trace_id: Filter by trace ID (uuid format)
        :type trace_id: str
        :param group_id: Filter by group ID (uuid format)
        :type group_id: str
        :param project_id: Filter by project ID
        :type project_id: int
        :param state: Filter by state
        :type state: TaskState
        :param status: Filter by status
        :type status: StatusType
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :type _request_timeout: int, tuple(int, int), optional
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the
                              authentication in the spec for a single request.
        :type _request_auth: dict, optional
        :param _content_type: force content-type for the request.
        :type _content_type: str, Optional
        :param _headers: set to override the headers for a single
                         request; this effectively ignores the headers
                         in the spec for a single request.
        :type _headers: dict, optional
        :param _host_index: set to override the host_index for a single
                            request; this effectively ignores the host_index
                            in the spec for a single request.
        :type _host_index: int, optional
        :return: Returns the result object.
        """  # noqa: E501

        _param = self._list_tasks_serialize(
            page=page,
            size=size,
            task_type=task_type,
            immediate=immediate,
            trace_id=trace_id,
            group_id=group_id,
            project_id=project_id,
            state=state,
            status=status,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index,
        )

        _response_types_map: dict[str, str | None] = {
            "200": "GenericResponseListTaskResp",
            "400": "GenericResponseAny",
            "401": "GenericResponseAny",
            "403": "GenericResponseAny",
            "500": "GenericResponseAny",
        }
        response_data = self.api_client.call_api(*_param, _request_timeout=_request_timeout)

        assert response_data is not None and isinstance(response_data, RESTResponse), (
            "Response data must be of type RESTResponse"
        )
        return response_data.response

    def _list_tasks_serialize(
        self,
        page,
        size,
        task_type,
        immediate,
        trace_id,
        group_id,
        project_id,
        state,
        status,
        _request_auth,
        _content_type,
        _headers,
        _host_index,
    ) -> RequestSerialized:
        _host = None

        _collection_formats: dict[str, str] = {}

        _path_params: dict[str, str] = {}
        _query_params: list[tuple[str, str]] = []
        _header_params: dict[str, str | None] = _headers or {}
        _form_params: list[tuple[str, str]] = []
        _files: dict[str, str | bytes | list[str] | list[bytes] | list[tuple[str, bytes]]] = {}
        _body_params: bytes | None = None

        # process the path parameters
        # process the query parameters
        if page is not None:
            _query_params.append(("page", page))

        if size is not None:
            _query_params.append(("size", size))

        if task_type is not None:
            _query_params.append(("task_type", task_type))

        if immediate is not None:
            _query_params.append(("immediate", immediate))

        if trace_id is not None:
            _query_params.append(("trace_id", trace_id))

        if group_id is not None:
            _query_params.append(("group_id", group_id))

        if project_id is not None:
            _query_params.append(("project_id", project_id))

        if state is not None:
            _query_params.append(("state", state.value))

        if status is not None:
            _query_params.append(("status", status.value))

        # process the header parameters
        # process the form parameters
        # process the body parameter

        # set the HTTP header `Accept`
        if "Accept" not in _header_params:
            _header_params["Accept"] = self.api_client.select_header_accept(["application/json"])

        # authentication setting
        _auth_settings: list[str] = ["BearerAuth"]

        return self.api_client.param_serialize(
            method="GET",
            resource_path="/api/v2/tasks",
            path_params=_path_params,
            query_params=_query_params,
            header_params=_header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            auth_settings=_auth_settings,
            collection_formats=_collection_formats,
            _host=_host,
            _request_auth=_request_auth,
        )
