# coding: utf-8

"""
    ICAT+ API

    ICAT+ RESTful API with Swagger

    The version of the OpenAPI document: 1.0.0
    Contact: demariaa@esrf.fr
    Generated by OpenAPI Generator (https://openapi-generator.tech)

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

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

from pydantic import Field, StrictBool, StrictStr, field_validator
from typing import Any, Dict, List, Optional
from typing_extensions import Annotated
from icat_plus_client.models.elasticsearch_session_id_stats_instrument_metrics_get_request_inner import ElasticsearchSessionIdStatsInstrumentMetricsGetRequestInner

from icat_plus_client.api_client import ApiClient, RequestSerialized
from icat_plus_client.api_response import ApiResponse
from icat_plus_client.rest import RESTResponseType


class ElasticSearchApi:
    """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 elasticsearch_session_id_datasets_msearch_get(
        self,
        session_id: Annotated[StrictStr, Field(description="session identifier provided by the metadata catalogue")],
        _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,
    ) -> object:
        """Proxy to elastic search server


        :param session_id: session identifier provided by the metadata catalogue (required)
        :type session_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._elasticsearch_session_id_datasets_msearch_get_serialize(
            session_id=session_id,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "object",
        }
        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 elasticsearch_session_id_datasets_msearch_get_with_http_info(
        self,
        session_id: Annotated[StrictStr, Field(description="session identifier provided by the metadata catalogue")],
        _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[object]:
        """Proxy to elastic search server


        :param session_id: session identifier provided by the metadata catalogue (required)
        :type session_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._elasticsearch_session_id_datasets_msearch_get_serialize(
            session_id=session_id,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "object",
        }
        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 elasticsearch_session_id_datasets_msearch_get_without_preload_content(
        self,
        session_id: Annotated[StrictStr, Field(description="session identifier provided by the metadata catalogue")],
        _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:
        """Proxy to elastic search server


        :param session_id: session identifier provided by the metadata catalogue (required)
        :type session_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._elasticsearch_session_id_datasets_msearch_get_serialize(
            session_id=session_id,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

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


    def _elasticsearch_session_id_datasets_msearch_get_serialize(
        self,
        session_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, Optional[str]] = _headers or {}
        _form_params: List[Tuple[str, str]] = []
        _files: Dict[str, Union[str, bytes]] = {}
        _body_params: Optional[bytes] = None

        # process the path parameters
        if session_id is not None:
            _path_params['sessionId'] = session_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] = [
        ]

        return self.api_client.param_serialize(
            method='GET',
            resource_path='/elasticsearch/{sessionId}/datasets/_msearch',
            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 elasticsearch_session_id_stats_histogram_get(
        self,
        session_id: Annotated[StrictStr, Field(description="session identifier provided by the metadata catalogue")],
        format: Annotated[Optional[StrictStr], Field(description="Output format. Default is json. csv_json returns a json with the embeded csv")] = None,
        metric: Annotated[Optional[StrictStr], Field(description="Metric that will be returned")] = None,
        aggregation: Annotated[Optional[StrictStr], Field(description="Parameter which data will be aggregated. Default is instrumentName")] = None,
        interval: Annotated[Optional[StrictStr], Field(description="Fixed interval used to group statistics in the time series.")] = None,
        start_date: Annotated[Optional[StrictStr], Field(description="Start of the time series")] = None,
        end_date: Annotated[Optional[StrictStr], Field(description="End of the time series")] = None,
        instrument_name: Annotated[Optional[StrictStr], Field(description="Filter by instrumentName or match all if empty")] = 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,
    ) -> None:
        """Gets time series statistics. Only administrator and instrumentScientists are allowed

        Gets time series statistics.

        :param session_id: session identifier provided by the metadata catalogue (required)
        :type session_id: str
        :param format: Output format. Default is json. csv_json returns a json with the embeded csv
        :type format: str
        :param metric: Metric that will be returned
        :type metric: str
        :param aggregation: Parameter which data will be aggregated. Default is instrumentName
        :type aggregation: str
        :param interval: Fixed interval used to group statistics in the time series.
        :type interval: str
        :param start_date: Start of the time series
        :type start_date: str
        :param end_date: End of the time series
        :type end_date: str
        :param instrument_name: Filter by instrumentName or match all if empty
        :type instrument_name: 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._elasticsearch_session_id_stats_histogram_get_serialize(
            session_id=session_id,
            format=format,
            metric=metric,
            aggregation=aggregation,
            interval=interval,
            start_date=start_date,
            end_date=end_date,
            instrument_name=instrument_name,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': None,
        }
        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 elasticsearch_session_id_stats_histogram_get_with_http_info(
        self,
        session_id: Annotated[StrictStr, Field(description="session identifier provided by the metadata catalogue")],
        format: Annotated[Optional[StrictStr], Field(description="Output format. Default is json. csv_json returns a json with the embeded csv")] = None,
        metric: Annotated[Optional[StrictStr], Field(description="Metric that will be returned")] = None,
        aggregation: Annotated[Optional[StrictStr], Field(description="Parameter which data will be aggregated. Default is instrumentName")] = None,
        interval: Annotated[Optional[StrictStr], Field(description="Fixed interval used to group statistics in the time series.")] = None,
        start_date: Annotated[Optional[StrictStr], Field(description="Start of the time series")] = None,
        end_date: Annotated[Optional[StrictStr], Field(description="End of the time series")] = None,
        instrument_name: Annotated[Optional[StrictStr], Field(description="Filter by instrumentName or match all if empty")] = 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[None]:
        """Gets time series statistics. Only administrator and instrumentScientists are allowed

        Gets time series statistics.

        :param session_id: session identifier provided by the metadata catalogue (required)
        :type session_id: str
        :param format: Output format. Default is json. csv_json returns a json with the embeded csv
        :type format: str
        :param metric: Metric that will be returned
        :type metric: str
        :param aggregation: Parameter which data will be aggregated. Default is instrumentName
        :type aggregation: str
        :param interval: Fixed interval used to group statistics in the time series.
        :type interval: str
        :param start_date: Start of the time series
        :type start_date: str
        :param end_date: End of the time series
        :type end_date: str
        :param instrument_name: Filter by instrumentName or match all if empty
        :type instrument_name: 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._elasticsearch_session_id_stats_histogram_get_serialize(
            session_id=session_id,
            format=format,
            metric=metric,
            aggregation=aggregation,
            interval=interval,
            start_date=start_date,
            end_date=end_date,
            instrument_name=instrument_name,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': None,
        }
        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 elasticsearch_session_id_stats_histogram_get_without_preload_content(
        self,
        session_id: Annotated[StrictStr, Field(description="session identifier provided by the metadata catalogue")],
        format: Annotated[Optional[StrictStr], Field(description="Output format. Default is json. csv_json returns a json with the embeded csv")] = None,
        metric: Annotated[Optional[StrictStr], Field(description="Metric that will be returned")] = None,
        aggregation: Annotated[Optional[StrictStr], Field(description="Parameter which data will be aggregated. Default is instrumentName")] = None,
        interval: Annotated[Optional[StrictStr], Field(description="Fixed interval used to group statistics in the time series.")] = None,
        start_date: Annotated[Optional[StrictStr], Field(description="Start of the time series")] = None,
        end_date: Annotated[Optional[StrictStr], Field(description="End of the time series")] = None,
        instrument_name: Annotated[Optional[StrictStr], Field(description="Filter by instrumentName or match all if empty")] = 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:
        """Gets time series statistics. Only administrator and instrumentScientists are allowed

        Gets time series statistics.

        :param session_id: session identifier provided by the metadata catalogue (required)
        :type session_id: str
        :param format: Output format. Default is json. csv_json returns a json with the embeded csv
        :type format: str
        :param metric: Metric that will be returned
        :type metric: str
        :param aggregation: Parameter which data will be aggregated. Default is instrumentName
        :type aggregation: str
        :param interval: Fixed interval used to group statistics in the time series.
        :type interval: str
        :param start_date: Start of the time series
        :type start_date: str
        :param end_date: End of the time series
        :type end_date: str
        :param instrument_name: Filter by instrumentName or match all if empty
        :type instrument_name: 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._elasticsearch_session_id_stats_histogram_get_serialize(
            session_id=session_id,
            format=format,
            metric=metric,
            aggregation=aggregation,
            interval=interval,
            start_date=start_date,
            end_date=end_date,
            instrument_name=instrument_name,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

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


    def _elasticsearch_session_id_stats_histogram_get_serialize(
        self,
        session_id,
        format,
        metric,
        aggregation,
        interval,
        start_date,
        end_date,
        instrument_name,
        _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, Optional[str]] = _headers or {}
        _form_params: List[Tuple[str, str]] = []
        _files: Dict[str, Union[str, bytes]] = {}
        _body_params: Optional[bytes] = None

        # process the path parameters
        if session_id is not None:
            _path_params['sessionId'] = session_id
        # process the query parameters
        if format is not None:
            
            _query_params.append(('format', format))
            
        if metric is not None:
            
            _query_params.append(('metric', metric))
            
        if aggregation is not None:
            
            _query_params.append(('aggregation', aggregation))
            
        if interval is not None:
            
            _query_params.append(('interval', interval))
            
        if start_date is not None:
            
            _query_params.append(('startDate', start_date))
            
        if end_date is not None:
            
            _query_params.append(('endDate', end_date))
            
        if instrument_name is not None:
            
            _query_params.append(('instrumentName', instrument_name))
            
        # process the header parameters
        # process the form parameters
        # process the body parameter




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

        return self.api_client.param_serialize(
            method='GET',
            resource_path='/elasticsearch/{sessionId}/stats/histogram',
            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 elasticsearch_session_id_stats_instrument_metrics_get(
        self,
        session_id: Annotated[StrictStr, Field(description="session identifier provided by the metadata catalogue")],
        elasticsearch_session_id_stats_instrument_metrics_get_request_inner: Annotated[List[ElasticsearchSessionIdStatsInstrumentMetricsGetRequestInner], Field(description="Array of date ranges")],
        instrument_name: Annotated[Optional[StrictStr], Field(description="Filter by instrumentName or match all if empty")] = None,
        open_data: Annotated[Optional[StrictBool], Field(description="If openData then the statistics will be calculated based on the datasets with a raw DOI which embargo period has expired")] = 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,
    ) -> object:
        """Given an array of dates it returns the statistics for each instrument

        metrics are avg_volume, sum_volume, avg_fileCount, sum_fileCount, datasetCount, avg_metadata, max_metadata, min_metadata

        :param session_id: session identifier provided by the metadata catalogue (required)
        :type session_id: str
        :param elasticsearch_session_id_stats_instrument_metrics_get_request_inner: Array of date ranges (required)
        :type elasticsearch_session_id_stats_instrument_metrics_get_request_inner: List[ElasticsearchSessionIdStatsInstrumentMetricsGetRequestInner]
        :param instrument_name: Filter by instrumentName or match all if empty
        :type instrument_name: str
        :param open_data: If openData then the statistics will be calculated based on the datasets with a raw DOI which embargo period has expired
        :type open_data: bool
        :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._elasticsearch_session_id_stats_instrument_metrics_get_serialize(
            session_id=session_id,
            elasticsearch_session_id_stats_instrument_metrics_get_request_inner=elasticsearch_session_id_stats_instrument_metrics_get_request_inner,
            instrument_name=instrument_name,
            open_data=open_data,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "object",
        }
        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 elasticsearch_session_id_stats_instrument_metrics_get_with_http_info(
        self,
        session_id: Annotated[StrictStr, Field(description="session identifier provided by the metadata catalogue")],
        elasticsearch_session_id_stats_instrument_metrics_get_request_inner: Annotated[List[ElasticsearchSessionIdStatsInstrumentMetricsGetRequestInner], Field(description="Array of date ranges")],
        instrument_name: Annotated[Optional[StrictStr], Field(description="Filter by instrumentName or match all if empty")] = None,
        open_data: Annotated[Optional[StrictBool], Field(description="If openData then the statistics will be calculated based on the datasets with a raw DOI which embargo period has expired")] = 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[object]:
        """Given an array of dates it returns the statistics for each instrument

        metrics are avg_volume, sum_volume, avg_fileCount, sum_fileCount, datasetCount, avg_metadata, max_metadata, min_metadata

        :param session_id: session identifier provided by the metadata catalogue (required)
        :type session_id: str
        :param elasticsearch_session_id_stats_instrument_metrics_get_request_inner: Array of date ranges (required)
        :type elasticsearch_session_id_stats_instrument_metrics_get_request_inner: List[ElasticsearchSessionIdStatsInstrumentMetricsGetRequestInner]
        :param instrument_name: Filter by instrumentName or match all if empty
        :type instrument_name: str
        :param open_data: If openData then the statistics will be calculated based on the datasets with a raw DOI which embargo period has expired
        :type open_data: bool
        :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._elasticsearch_session_id_stats_instrument_metrics_get_serialize(
            session_id=session_id,
            elasticsearch_session_id_stats_instrument_metrics_get_request_inner=elasticsearch_session_id_stats_instrument_metrics_get_request_inner,
            instrument_name=instrument_name,
            open_data=open_data,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "object",
        }
        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 elasticsearch_session_id_stats_instrument_metrics_get_without_preload_content(
        self,
        session_id: Annotated[StrictStr, Field(description="session identifier provided by the metadata catalogue")],
        elasticsearch_session_id_stats_instrument_metrics_get_request_inner: Annotated[List[ElasticsearchSessionIdStatsInstrumentMetricsGetRequestInner], Field(description="Array of date ranges")],
        instrument_name: Annotated[Optional[StrictStr], Field(description="Filter by instrumentName or match all if empty")] = None,
        open_data: Annotated[Optional[StrictBool], Field(description="If openData then the statistics will be calculated based on the datasets with a raw DOI which embargo period has expired")] = 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:
        """Given an array of dates it returns the statistics for each instrument

        metrics are avg_volume, sum_volume, avg_fileCount, sum_fileCount, datasetCount, avg_metadata, max_metadata, min_metadata

        :param session_id: session identifier provided by the metadata catalogue (required)
        :type session_id: str
        :param elasticsearch_session_id_stats_instrument_metrics_get_request_inner: Array of date ranges (required)
        :type elasticsearch_session_id_stats_instrument_metrics_get_request_inner: List[ElasticsearchSessionIdStatsInstrumentMetricsGetRequestInner]
        :param instrument_name: Filter by instrumentName or match all if empty
        :type instrument_name: str
        :param open_data: If openData then the statistics will be calculated based on the datasets with a raw DOI which embargo period has expired
        :type open_data: bool
        :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._elasticsearch_session_id_stats_instrument_metrics_get_serialize(
            session_id=session_id,
            elasticsearch_session_id_stats_instrument_metrics_get_request_inner=elasticsearch_session_id_stats_instrument_metrics_get_request_inner,
            instrument_name=instrument_name,
            open_data=open_data,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

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


    def _elasticsearch_session_id_stats_instrument_metrics_get_serialize(
        self,
        session_id,
        elasticsearch_session_id_stats_instrument_metrics_get_request_inner,
        instrument_name,
        open_data,
        _request_auth,
        _content_type,
        _headers,
        _host_index,
    ) -> RequestSerialized:

        _host = None

        _collection_formats: Dict[str, str] = {
            'ElasticsearchSessionIdStatsInstrumentMetricsGetRequestInner': '',
        }

        _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, Union[str, bytes]] = {}
        _body_params: Optional[bytes] = None

        # process the path parameters
        if session_id is not None:
            _path_params['sessionId'] = session_id
        # process the query parameters
        if instrument_name is not None:
            
            _query_params.append(('instrumentName', instrument_name))
            
        if open_data is not None:
            
            _query_params.append(('openData', open_data))
            
        # process the header parameters
        # process the form parameters
        # process the body parameter
        if elasticsearch_session_id_stats_instrument_metrics_get_request_inner is not None:
            _body_params = elasticsearch_session_id_stats_instrument_metrics_get_request_inner


        # set the HTTP header `Accept`
        if 'Accept' not in _header_params:
            _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] = [
        ]

        return self.api_client.param_serialize(
            method='GET',
            resource_path='/elasticsearch/{sessionId}/stats/instrument/metrics',
            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
        )


