# coding: utf-8

"""
    AI Hub API

    The AI Hub REST API. Please see https://docs.instabase.com for more details.

    The version of the OpenAPI document: 0.1
    Contact: support@instabase.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

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


import io
import warnings

from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt
from typing import Dict, List, Optional, Tuple, Union, Any

try:
    from typing import Annotated
except ImportError:
    from typing_extensions import Annotated

from pydantic import Field
from typing_extensions import Annotated
from pydantic import StrictBool, StrictBytes, StrictInt, StrictStr

from typing import Any, Dict, List, Optional, Union

from aihub.models.results_response import ResultsResponse
from aihub.models.run import Run
from aihub.models.run_app_request import RunAppRequest

from aihub.api_client import ApiClient
from aihub.api_response import ApiResponse
from aihub.rest import RESTResponseType


class RunApi:
    """NOTE: This class is auto generated by OpenAPI Generator
    Ref: https://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_run_results(
        self,
        id: Annotated[StrictStr, Field(description="The run ID.")],
        file_offset: Annotated[Optional[StrictInt], Field(description="Offset for file retrieval.")] = None,
        include_confidence_scores: Annotated[Optional[StrictBool], Field(description="Whether to include confidence scores in the results.")] = None,
        include_source_info: Annotated[Optional[StrictBool], Field(description="Whether to include source information in the results.")] = None,
        include_review_results: Annotated[Optional[StrictBool], Field(description="Whether to include human review data in the results.")] = None,
        include_validation_results: Annotated[Optional[StrictBool], Field(description="Whether to include validation data in the results.")] = None,
        ib_context: Annotated[Optional[StrictStr], Field(description="Optional header to provide additional context.")] = None,
        _request_timeout: Union[
            None,
            Annotated[StrictFloat, Field(gt=0)],
            Tuple[
                Annotated[StrictFloat, Field(gt=0)],
                Annotated[StrictFloat, Field(gt=0)]
            ]
        ] = None,
        _request_auth: Optional[Dict[StrictStr, Any]] = None,
        _content_type: Optional[StrictStr] = None,
        _headers: Optional[Dict[StrictStr, Any]] = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> ResultsResponse:
        """Retrieve run results


        :param id: The run ID. (required)
        :type id: str
        :param file_offset: Offset for file retrieval.
        :type file_offset: int
        :param include_confidence_scores: Whether to include confidence scores in the results.
        :type include_confidence_scores: bool
        :param include_source_info: Whether to include source information in the results.
        :type include_source_info: bool
        :param include_review_results: Whether to include human review data in the results.
        :type include_review_results: bool
        :param include_validation_results: Whether to include validation data in the results.
        :type include_validation_results: bool
        :param ib_context: Optional header to provide additional context.
        :type ib_context: 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_run_results_serialize(
            id=id,
            file_offset=file_offset,
            include_confidence_scores=include_confidence_scores,
            include_source_info=include_source_info,
            include_review_results=include_review_results,
            include_validation_results=include_validation_results,
            ib_context=ib_context,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "ResultsResponse",
            
            
        }
        response_data = self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        ).data


    @validate_call
    def get_run_results_with_http_info(
        self,
        id: Annotated[StrictStr, Field(description="The run ID.")],
        file_offset: Annotated[Optional[StrictInt], Field(description="Offset for file retrieval.")] = None,
        include_confidence_scores: Annotated[Optional[StrictBool], Field(description="Whether to include confidence scores in the results.")] = None,
        include_source_info: Annotated[Optional[StrictBool], Field(description="Whether to include source information in the results.")] = None,
        include_review_results: Annotated[Optional[StrictBool], Field(description="Whether to include human review data in the results.")] = None,
        include_validation_results: Annotated[Optional[StrictBool], Field(description="Whether to include validation data in the results.")] = None,
        ib_context: Annotated[Optional[StrictStr], Field(description="Optional header to provide additional context.")] = None,
        _request_timeout: Union[
            None,
            Annotated[StrictFloat, Field(gt=0)],
            Tuple[
                Annotated[StrictFloat, Field(gt=0)],
                Annotated[StrictFloat, Field(gt=0)]
            ]
        ] = None,
        _request_auth: Optional[Dict[StrictStr, Any]] = None,
        _content_type: Optional[StrictStr] = None,
        _headers: Optional[Dict[StrictStr, Any]] = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> ApiResponse[ResultsResponse]:
        """Retrieve run results


        :param id: The run ID. (required)
        :type id: str
        :param file_offset: Offset for file retrieval.
        :type file_offset: int
        :param include_confidence_scores: Whether to include confidence scores in the results.
        :type include_confidence_scores: bool
        :param include_source_info: Whether to include source information in the results.
        :type include_source_info: bool
        :param include_review_results: Whether to include human review data in the results.
        :type include_review_results: bool
        :param include_validation_results: Whether to include validation data in the results.
        :type include_validation_results: bool
        :param ib_context: Optional header to provide additional context.
        :type ib_context: 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_run_results_serialize(
            id=id,
            file_offset=file_offset,
            include_confidence_scores=include_confidence_scores,
            include_source_info=include_source_info,
            include_review_results=include_review_results,
            include_validation_results=include_validation_results,
            ib_context=ib_context,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "ResultsResponse",
            
            
        }
        response_data = self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        )


    @validate_call
    def get_run_results_without_preload_content(
        self,
        id: Annotated[StrictStr, Field(description="The run ID.")],
        file_offset: Annotated[Optional[StrictInt], Field(description="Offset for file retrieval.")] = None,
        include_confidence_scores: Annotated[Optional[StrictBool], Field(description="Whether to include confidence scores in the results.")] = None,
        include_source_info: Annotated[Optional[StrictBool], Field(description="Whether to include source information in the results.")] = None,
        include_review_results: Annotated[Optional[StrictBool], Field(description="Whether to include human review data in the results.")] = None,
        include_validation_results: Annotated[Optional[StrictBool], Field(description="Whether to include validation data in the results.")] = None,
        ib_context: Annotated[Optional[StrictStr], Field(description="Optional header to provide additional context.")] = None,
        _request_timeout: Union[
            None,
            Annotated[StrictFloat, Field(gt=0)],
            Tuple[
                Annotated[StrictFloat, Field(gt=0)],
                Annotated[StrictFloat, Field(gt=0)]
            ]
        ] = None,
        _request_auth: Optional[Dict[StrictStr, Any]] = None,
        _content_type: Optional[StrictStr] = None,
        _headers: Optional[Dict[StrictStr, Any]] = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> RESTResponseType:
        """Retrieve run results


        :param id: The run ID. (required)
        :type id: str
        :param file_offset: Offset for file retrieval.
        :type file_offset: int
        :param include_confidence_scores: Whether to include confidence scores in the results.
        :type include_confidence_scores: bool
        :param include_source_info: Whether to include source information in the results.
        :type include_source_info: bool
        :param include_review_results: Whether to include human review data in the results.
        :type include_review_results: bool
        :param include_validation_results: Whether to include validation data in the results.
        :type include_validation_results: bool
        :param ib_context: Optional header to provide additional context.
        :type ib_context: 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_run_results_serialize(
            id=id,
            file_offset=file_offset,
            include_confidence_scores=include_confidence_scores,
            include_source_info=include_source_info,
            include_review_results=include_review_results,
            include_validation_results=include_validation_results,
            ib_context=ib_context,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "ResultsResponse",
            
            
        }
        response_data = self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        return response_data.response


    def _get_run_results_serialize(
        self,
        id,
        file_offset,
        include_confidence_scores,
        include_source_info,
        include_review_results,
        include_validation_results,
        ib_context,
        _request_auth,
        _content_type,
        _headers,
        _host_index,
    ) -> Tuple:

        _host = None

        _collection_formats: Dict[str, str] = {
            
        }

        _path_params: Dict[str, str] = {}
        _query_params: List[Tuple[str, str]] = []
        _header_params: Dict[str, Optional[str]] = _headers or {}
        _form_params: List[Tuple[str, str]] = []
        _files: Dict[str, str] = {}
        _body_params: Optional[bytes] = None

        # process the path parameters
        if id is not None:
            _path_params['id'] = id
        # process the query parameters
        if file_offset is not None:
            
            _query_params.append(('file_offset', file_offset))
            
        if include_confidence_scores is not None:
            
            _query_params.append(('include_confidence_scores', include_confidence_scores))
            
        if include_source_info is not None:
            
            _query_params.append(('include_source_info', include_source_info))
            
        if include_review_results is not None:
            
            _query_params.append(('include_review_results', include_review_results))
            
        if include_validation_results is not None:
            
            _query_params.append(('include_validation_results', include_validation_results))
            
        # process the header parameters
        if ib_context is not None:
            _header_params['IB-Context'] = ib_context
        # process the form parameters
        # process the body parameter


        # set the HTTP header `Accept`
        _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='/v2/apps/runs/{id}/results',
            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 get_run_status(
        self,
        id: Annotated[StrictStr, Field(description="The run ID.")],
        ib_context: Annotated[Optional[StrictStr], Field(description="Optional header to provide additional context.")] = None,
        _request_timeout: Union[
            None,
            Annotated[StrictFloat, Field(gt=0)],
            Tuple[
                Annotated[StrictFloat, Field(gt=0)],
                Annotated[StrictFloat, Field(gt=0)]
            ]
        ] = None,
        _request_auth: Optional[Dict[StrictStr, Any]] = None,
        _content_type: Optional[StrictStr] = None,
        _headers: Optional[Dict[StrictStr, Any]] = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> Run:
        """Get the status of a run.


        :param id: The run ID. (required)
        :type id: str
        :param ib_context: Optional header to provide additional context.
        :type ib_context: 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_run_status_serialize(
            id=id,
            ib_context=ib_context,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "Run",
            
            
        }
        response_data = self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        ).data


    @validate_call
    def get_run_status_with_http_info(
        self,
        id: Annotated[StrictStr, Field(description="The run ID.")],
        ib_context: Annotated[Optional[StrictStr], Field(description="Optional header to provide additional context.")] = None,
        _request_timeout: Union[
            None,
            Annotated[StrictFloat, Field(gt=0)],
            Tuple[
                Annotated[StrictFloat, Field(gt=0)],
                Annotated[StrictFloat, Field(gt=0)]
            ]
        ] = None,
        _request_auth: Optional[Dict[StrictStr, Any]] = None,
        _content_type: Optional[StrictStr] = None,
        _headers: Optional[Dict[StrictStr, Any]] = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> ApiResponse[Run]:
        """Get the status of a run.


        :param id: The run ID. (required)
        :type id: str
        :param ib_context: Optional header to provide additional context.
        :type ib_context: 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_run_status_serialize(
            id=id,
            ib_context=ib_context,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "Run",
            
            
        }
        response_data = self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        )


    @validate_call
    def get_run_status_without_preload_content(
        self,
        id: Annotated[StrictStr, Field(description="The run ID.")],
        ib_context: Annotated[Optional[StrictStr], Field(description="Optional header to provide additional context.")] = None,
        _request_timeout: Union[
            None,
            Annotated[StrictFloat, Field(gt=0)],
            Tuple[
                Annotated[StrictFloat, Field(gt=0)],
                Annotated[StrictFloat, Field(gt=0)]
            ]
        ] = None,
        _request_auth: Optional[Dict[StrictStr, Any]] = None,
        _content_type: Optional[StrictStr] = None,
        _headers: Optional[Dict[StrictStr, Any]] = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> RESTResponseType:
        """Get the status of a run.


        :param id: The run ID. (required)
        :type id: str
        :param ib_context: Optional header to provide additional context.
        :type ib_context: 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_run_status_serialize(
            id=id,
            ib_context=ib_context,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "Run",
            
            
        }
        response_data = self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        return response_data.response


    def _get_run_status_serialize(
        self,
        id,
        ib_context,
        _request_auth,
        _content_type,
        _headers,
        _host_index,
    ) -> Tuple:

        _host = None

        _collection_formats: Dict[str, str] = {
            
        }

        _path_params: Dict[str, str] = {}
        _query_params: List[Tuple[str, str]] = []
        _header_params: Dict[str, Optional[str]] = _headers or {}
        _form_params: List[Tuple[str, str]] = []
        _files: Dict[str, str] = {}
        _body_params: Optional[bytes] = None

        # process the path parameters
        if id is not None:
            _path_params['id'] = id
        # process the query parameters
        # process the header parameters
        if ib_context is not None:
            _header_params['IB-Context'] = ib_context
        # process the form parameters
        # process the body parameter


        # set the HTTP header `Accept`
        _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='/v2/apps/runs/{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 run_app(
        self,
        run_app_request: RunAppRequest,
        ib_context: Annotated[Optional[StrictStr], Field(description="Optional header to provide additional context.")] = None,
        _request_timeout: Union[
            None,
            Annotated[StrictFloat, Field(gt=0)],
            Tuple[
                Annotated[StrictFloat, Field(gt=0)],
                Annotated[StrictFloat, Field(gt=0)]
            ]
        ] = None,
        _request_auth: Optional[Dict[StrictStr, Any]] = None,
        _content_type: Optional[StrictStr] = None,
        _headers: Optional[Dict[StrictStr, Any]] = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> Run:
        """Run a given app.


        :param run_app_request: (required)
        :type run_app_request: RunAppRequest
        :param ib_context: Optional header to provide additional context.
        :type ib_context: 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._run_app_serialize(
            run_app_request=run_app_request,
            ib_context=ib_context,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "Run",
            
            
        }
        response_data = self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        ).data


    @validate_call
    def run_app_with_http_info(
        self,
        run_app_request: RunAppRequest,
        ib_context: Annotated[Optional[StrictStr], Field(description="Optional header to provide additional context.")] = None,
        _request_timeout: Union[
            None,
            Annotated[StrictFloat, Field(gt=0)],
            Tuple[
                Annotated[StrictFloat, Field(gt=0)],
                Annotated[StrictFloat, Field(gt=0)]
            ]
        ] = None,
        _request_auth: Optional[Dict[StrictStr, Any]] = None,
        _content_type: Optional[StrictStr] = None,
        _headers: Optional[Dict[StrictStr, Any]] = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> ApiResponse[Run]:
        """Run a given app.


        :param run_app_request: (required)
        :type run_app_request: RunAppRequest
        :param ib_context: Optional header to provide additional context.
        :type ib_context: 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._run_app_serialize(
            run_app_request=run_app_request,
            ib_context=ib_context,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "Run",
            
            
        }
        response_data = self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        )


    @validate_call
    def run_app_without_preload_content(
        self,
        run_app_request: RunAppRequest,
        ib_context: Annotated[Optional[StrictStr], Field(description="Optional header to provide additional context.")] = None,
        _request_timeout: Union[
            None,
            Annotated[StrictFloat, Field(gt=0)],
            Tuple[
                Annotated[StrictFloat, Field(gt=0)],
                Annotated[StrictFloat, Field(gt=0)]
            ]
        ] = None,
        _request_auth: Optional[Dict[StrictStr, Any]] = None,
        _content_type: Optional[StrictStr] = None,
        _headers: Optional[Dict[StrictStr, Any]] = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> RESTResponseType:
        """Run a given app.


        :param run_app_request: (required)
        :type run_app_request: RunAppRequest
        :param ib_context: Optional header to provide additional context.
        :type ib_context: 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._run_app_serialize(
            run_app_request=run_app_request,
            ib_context=ib_context,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "Run",
            
            
        }
        response_data = self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        return response_data.response


    def _run_app_serialize(
        self,
        run_app_request,
        ib_context,
        _request_auth,
        _content_type,
        _headers,
        _host_index,
    ) -> Tuple:

        _host = None

        _collection_formats: Dict[str, str] = {
            
        }

        _path_params: Dict[str, str] = {}
        _query_params: List[Tuple[str, str]] = []
        _header_params: Dict[str, Optional[str]] = _headers or {}
        _form_params: List[Tuple[str, str]] = []
        _files: Dict[str, str] = {}
        _body_params: Optional[bytes] = None

        # process the path parameters
        # process the query parameters
        # process the header parameters
        if ib_context is not None:
            _header_params['IB-Context'] = ib_context
        # process the form parameters
        # process the body parameter
        if run_app_request is not None:
            _body_params = run_app_request


        # set the HTTP header `Accept`
        _header_params['Accept'] = self.api_client.select_header_accept(
            [
                'application/json'
            ]
        )

        # set the HTTP header `Content-Type`
        if _content_type:
            _header_params['Content-Type'] = _content_type
        else:
            _default_content_type = (
                self.api_client.select_header_content_type(
                    [
                        'application/json'
                    ]
                )
            )
            if _default_content_type is not None:
                _header_params['Content-Type'] = _default_content_type

        # authentication setting
        _auth_settings: List[str] = [
            'bearerAuth'
        ]

        return self.api_client.param_serialize(
            method='POST',
            resource_path='/v2/apps/runs',
            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 run_app_sync(
        self,
        ib_context: Annotated[Optional[StrictStr], Field(description="Optional header to provide additional context.")] = None,
        app_name: Annotated[Optional[StrictStr], Field(description="The name of the app to run.")] = None,
        app_id: Annotated[Optional[StrictStr], Field(description="The ID of the app to run.")] = None,
        files: Optional[List[Union[StrictBytes, StrictStr]]] = None,
        owner: Annotated[Optional[StrictStr], Field(description="Owner of the app run.")] = None,
        settings: Annotated[Optional[Dict[str, Any]], Field(description="JSON object containing settings for the app run.")] = None,
        _request_timeout: Union[
            None,
            Annotated[StrictFloat, Field(gt=0)],
            Tuple[
                Annotated[StrictFloat, Field(gt=0)],
                Annotated[StrictFloat, Field(gt=0)]
            ]
        ] = None,
        _request_auth: Optional[Dict[StrictStr, Any]] = None,
        _content_type: Optional[StrictStr] = None,
        _headers: Optional[Dict[StrictStr, Any]] = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> ResultsResponse:
        """Run a given app and return the results.


        :param ib_context: Optional header to provide additional context.
        :type ib_context: str
        :param app_name: The name of the app to run.
        :type app_name: str
        :param app_id: The ID of the app to run.
        :type app_id: str
        :param files:
        :type files: List[bytearray]
        :param owner: Owner of the app run.
        :type owner: str
        :param settings: JSON object containing settings for the app run.
        :type settings: Dict[str, object]
        :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._run_app_sync_serialize(
            ib_context=ib_context,
            app_name=app_name,
            app_id=app_id,
            files=files,
            owner=owner,
            settings=settings,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "ResultsResponse",
            '202': "ResultsResponse",
            
            
        }
        response_data = self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        ).data


    @validate_call
    def run_app_sync_with_http_info(
        self,
        ib_context: Annotated[Optional[StrictStr], Field(description="Optional header to provide additional context.")] = None,
        app_name: Annotated[Optional[StrictStr], Field(description="The name of the app to run.")] = None,
        app_id: Annotated[Optional[StrictStr], Field(description="The ID of the app to run.")] = None,
        files: Optional[List[Union[StrictBytes, StrictStr]]] = None,
        owner: Annotated[Optional[StrictStr], Field(description="Owner of the app run.")] = None,
        settings: Annotated[Optional[Dict[str, Any]], Field(description="JSON object containing settings for the app run.")] = None,
        _request_timeout: Union[
            None,
            Annotated[StrictFloat, Field(gt=0)],
            Tuple[
                Annotated[StrictFloat, Field(gt=0)],
                Annotated[StrictFloat, Field(gt=0)]
            ]
        ] = None,
        _request_auth: Optional[Dict[StrictStr, Any]] = None,
        _content_type: Optional[StrictStr] = None,
        _headers: Optional[Dict[StrictStr, Any]] = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> ApiResponse[ResultsResponse]:
        """Run a given app and return the results.


        :param ib_context: Optional header to provide additional context.
        :type ib_context: str
        :param app_name: The name of the app to run.
        :type app_name: str
        :param app_id: The ID of the app to run.
        :type app_id: str
        :param files:
        :type files: List[bytearray]
        :param owner: Owner of the app run.
        :type owner: str
        :param settings: JSON object containing settings for the app run.
        :type settings: Dict[str, object]
        :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._run_app_sync_serialize(
            ib_context=ib_context,
            app_name=app_name,
            app_id=app_id,
            files=files,
            owner=owner,
            settings=settings,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "ResultsResponse",
            '202': "ResultsResponse",
            
            
        }
        response_data = self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        )


    @validate_call
    def run_app_sync_without_preload_content(
        self,
        ib_context: Annotated[Optional[StrictStr], Field(description="Optional header to provide additional context.")] = None,
        app_name: Annotated[Optional[StrictStr], Field(description="The name of the app to run.")] = None,
        app_id: Annotated[Optional[StrictStr], Field(description="The ID of the app to run.")] = None,
        files: Optional[List[Union[StrictBytes, StrictStr]]] = None,
        owner: Annotated[Optional[StrictStr], Field(description="Owner of the app run.")] = None,
        settings: Annotated[Optional[Dict[str, Any]], Field(description="JSON object containing settings for the app run.")] = None,
        _request_timeout: Union[
            None,
            Annotated[StrictFloat, Field(gt=0)],
            Tuple[
                Annotated[StrictFloat, Field(gt=0)],
                Annotated[StrictFloat, Field(gt=0)]
            ]
        ] = None,
        _request_auth: Optional[Dict[StrictStr, Any]] = None,
        _content_type: Optional[StrictStr] = None,
        _headers: Optional[Dict[StrictStr, Any]] = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> RESTResponseType:
        """Run a given app and return the results.


        :param ib_context: Optional header to provide additional context.
        :type ib_context: str
        :param app_name: The name of the app to run.
        :type app_name: str
        :param app_id: The ID of the app to run.
        :type app_id: str
        :param files:
        :type files: List[bytearray]
        :param owner: Owner of the app run.
        :type owner: str
        :param settings: JSON object containing settings for the app run.
        :type settings: Dict[str, object]
        :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._run_app_sync_serialize(
            ib_context=ib_context,
            app_name=app_name,
            app_id=app_id,
            files=files,
            owner=owner,
            settings=settings,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "ResultsResponse",
            '202': "ResultsResponse",
            
            
        }
        response_data = self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        return response_data.response


    def _run_app_sync_serialize(
        self,
        ib_context,
        app_name,
        app_id,
        files,
        owner,
        settings,
        _request_auth,
        _content_type,
        _headers,
        _host_index,
    ) -> Tuple:

        _host = None

        _collection_formats: Dict[str, str] = {
            
            'files': 'csv',
        }

        _path_params: Dict[str, str] = {}
        _query_params: List[Tuple[str, str]] = []
        _header_params: Dict[str, Optional[str]] = _headers or {}
        _form_params: List[Tuple[str, str]] = []
        _files: Dict[str, str] = {}
        _body_params: Optional[bytes] = None

        # process the path parameters
        # process the query parameters
        # process the header parameters
        if ib_context is not None:
            _header_params['IB-Context'] = ib_context
        # process the form parameters
        if app_name is not None:
            _form_params.append(('app_name', app_name))
        if app_id is not None:
            _form_params.append(('app_id', app_id))
        if files is not None:
            _files['files'] = files
        if owner is not None:
            _form_params.append(('owner', owner))
        if settings is not None:
            _form_params.append(('settings', settings))
        # process the body parameter


        # set the HTTP header `Accept`
        _header_params['Accept'] = self.api_client.select_header_accept(
            [
                'application/json'
            ]
        )

        # set the HTTP header `Content-Type`
        if _content_type:
            _header_params['Content-Type'] = _content_type
        else:
            _default_content_type = (
                self.api_client.select_header_content_type(
                    [
                        'multipart/form-data'
                    ]
                )
            )
            if _default_content_type is not None:
                _header_params['Content-Type'] = _default_content_type

        # authentication setting
        _auth_settings: List[str] = [
            'bearerAuth'
        ]

        return self.api_client.param_serialize(
            method='POST',
            resource_path='/v2/apps/runs/run',
            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
        )


