# coding: utf-8

"""
    FastAPI

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)  # noqa: E501

    The version of the OpenAPI document: 0.1.0
    Generated by: https://openapi-generator.tech
"""


from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from generic_elasticsearch.api_client import ApiClient
from generic_elasticsearch.exceptions import (  # noqa: F401
    ApiTypeError,
    ApiValueError
)


class ElasticsearchApi(object):
    """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):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client

    def delete_from_es_indexing_table_name_index_delete(self, table_name, index, **kwargs):  # noqa: E501
        """Delete From Es  # noqa: E501

        Remove an indexed item from an ElasticSearch table  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.delete_from_es_indexing_table_name_index_delete(table_name, index, async_req=True)
        >>> result = thread.get()

        :param async_req bool: execute request asynchronously
        :param str table_name: (required)
        :param str index: (required)
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :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.
        :return: OperationResult
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        return self.delete_from_es_indexing_table_name_index_delete_with_http_info(table_name, index, **kwargs)  # noqa: E501

    def delete_from_es_indexing_table_name_index_delete_with_http_info(self, table_name, index, **kwargs):  # noqa: E501
        """Delete From Es  # noqa: E501

        Remove an indexed item from an ElasticSearch table  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.delete_from_es_indexing_table_name_index_delete_with_http_info(table_name, index, async_req=True)
        >>> result = thread.get()

        :param async_req bool: execute request asynchronously
        :param str table_name: (required)
        :param str index: (required)
        :param _return_http_data_only: response data without head status code
                                       and headers
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :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.
        :return: tuple(OperationResult, status_code(int), headers(HTTPHeaderDict))
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = [
            'table_name',
            'index'
        ]
        all_params.extend(
            [
                'async_req',
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout'
            ]
        )

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method delete_from_es_indexing_table_name_index_delete" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']
        # verify the required parameter 'table_name' is set
        if self.api_client.client_side_validation and ('table_name' not in local_var_params or  # noqa: E501
                                                        local_var_params['table_name'] is None):  # noqa: E501
            raise ApiValueError("Missing the required parameter `table_name` when calling `delete_from_es_indexing_table_name_index_delete`")  # noqa: E501
        # verify the required parameter 'index' is set
        if self.api_client.client_side_validation and ('index' not in local_var_params or  # noqa: E501
                                                        local_var_params['index'] is None):  # noqa: E501
            raise ApiValueError("Missing the required parameter `index` when calling `delete_from_es_indexing_table_name_index_delete`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'table_name' in local_var_params:
            path_params['table_name'] = local_var_params['table_name']  # noqa: E501
        if 'index' in local_var_params:
            path_params['index'] = local_var_params['index']  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = ['HTTPBasic']  # noqa: E501

        return self.api_client.call_api(
            '/indexing/{table_name}/{index}', 'DELETE',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='OperationResult',  # noqa: E501
            auth_settings=auth_settings,
            async_req=local_var_params.get('async_req'),
            _return_http_data_only=local_var_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=local_var_params.get('_preload_content', True),
            _request_timeout=local_var_params.get('_request_timeout'),
            collection_formats=collection_formats)

    def get_from_es_indexing_table_name_post(self, table_name, query, **kwargs):  # noqa: E501
        """Get From Es  # noqa: E501

        Run a query on an Elasticsearch Table  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.get_from_es_indexing_table_name_post(table_name, query, async_req=True)
        >>> result = thread.get()

        :param async_req bool: execute request asynchronously
        :param str table_name: (required)
        :param Query query: (required)
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :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.
        :return: SearchResults
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        return self.get_from_es_indexing_table_name_post_with_http_info(table_name, query, **kwargs)  # noqa: E501

    def get_from_es_indexing_table_name_post_with_http_info(self, table_name, query, **kwargs):  # noqa: E501
        """Get From Es  # noqa: E501

        Run a query on an Elasticsearch Table  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.get_from_es_indexing_table_name_post_with_http_info(table_name, query, async_req=True)
        >>> result = thread.get()

        :param async_req bool: execute request asynchronously
        :param str table_name: (required)
        :param Query query: (required)
        :param _return_http_data_only: response data without head status code
                                       and headers
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :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.
        :return: tuple(SearchResults, status_code(int), headers(HTTPHeaderDict))
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = [
            'table_name',
            'query'
        ]
        all_params.extend(
            [
                'async_req',
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout'
            ]
        )

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_from_es_indexing_table_name_post" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']
        # verify the required parameter 'table_name' is set
        if self.api_client.client_side_validation and ('table_name' not in local_var_params or  # noqa: E501
                                                        local_var_params['table_name'] is None):  # noqa: E501
            raise ApiValueError("Missing the required parameter `table_name` when calling `get_from_es_indexing_table_name_post`")  # noqa: E501
        # verify the required parameter 'query' is set
        if self.api_client.client_side_validation and ('query' not in local_var_params or  # noqa: E501
                                                        local_var_params['query'] is None):  # noqa: E501
            raise ApiValueError("Missing the required parameter `query` when calling `get_from_es_indexing_table_name_post`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'table_name' in local_var_params:
            path_params['table_name'] = local_var_params['table_name']  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'query' in local_var_params:
            body_params = local_var_params['query']
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.select_header_content_type(  # noqa: E501
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = ['HTTPBasic']  # noqa: E501

        return self.api_client.call_api(
            '/indexing/{table_name}', 'POST',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='SearchResults',  # noqa: E501
            auth_settings=auth_settings,
            async_req=local_var_params.get('async_req'),
            _return_http_data_only=local_var_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=local_var_params.get('_preload_content', True),
            _request_timeout=local_var_params.get('_request_timeout'),
            collection_formats=collection_formats)

    def put_into_es_indexing_table_name_index_put(self, table_name, index, insert, **kwargs):  # noqa: E501
        """Put Into Es  # noqa: E501

        Upsert a new item into elasticsearch  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.put_into_es_indexing_table_name_index_put(table_name, index, insert, async_req=True)
        >>> result = thread.get()

        :param async_req bool: execute request asynchronously
        :param str table_name: (required)
        :param str index: (required)
        :param Insert insert: (required)
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :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.
        :return: OperationResult
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        return self.put_into_es_indexing_table_name_index_put_with_http_info(table_name, index, insert, **kwargs)  # noqa: E501

    def put_into_es_indexing_table_name_index_put_with_http_info(self, table_name, index, insert, **kwargs):  # noqa: E501
        """Put Into Es  # noqa: E501

        Upsert a new item into elasticsearch  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.put_into_es_indexing_table_name_index_put_with_http_info(table_name, index, insert, async_req=True)
        >>> result = thread.get()

        :param async_req bool: execute request asynchronously
        :param str table_name: (required)
        :param str index: (required)
        :param Insert insert: (required)
        :param _return_http_data_only: response data without head status code
                                       and headers
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :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.
        :return: tuple(OperationResult, status_code(int), headers(HTTPHeaderDict))
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = [
            'table_name',
            'index',
            'insert'
        ]
        all_params.extend(
            [
                'async_req',
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout'
            ]
        )

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method put_into_es_indexing_table_name_index_put" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']
        # verify the required parameter 'table_name' is set
        if self.api_client.client_side_validation and ('table_name' not in local_var_params or  # noqa: E501
                                                        local_var_params['table_name'] is None):  # noqa: E501
            raise ApiValueError("Missing the required parameter `table_name` when calling `put_into_es_indexing_table_name_index_put`")  # noqa: E501
        # verify the required parameter 'index' is set
        if self.api_client.client_side_validation and ('index' not in local_var_params or  # noqa: E501
                                                        local_var_params['index'] is None):  # noqa: E501
            raise ApiValueError("Missing the required parameter `index` when calling `put_into_es_indexing_table_name_index_put`")  # noqa: E501
        # verify the required parameter 'insert' is set
        if self.api_client.client_side_validation and ('insert' not in local_var_params or  # noqa: E501
                                                        local_var_params['insert'] is None):  # noqa: E501
            raise ApiValueError("Missing the required parameter `insert` when calling `put_into_es_indexing_table_name_index_put`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'table_name' in local_var_params:
            path_params['table_name'] = local_var_params['table_name']  # noqa: E501
        if 'index' in local_var_params:
            path_params['index'] = local_var_params['index']  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'insert' in local_var_params:
            body_params = local_var_params['insert']
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.select_header_content_type(  # noqa: E501
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = ['HTTPBasic']  # noqa: E501

        return self.api_client.call_api(
            '/indexing/{table_name}/{index}', 'PUT',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='OperationResult',  # noqa: E501
            auth_settings=auth_settings,
            async_req=local_var_params.get('async_req'),
            _return_http_data_only=local_var_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=local_var_params.get('_preload_content', True),
            _request_timeout=local_var_params.get('_request_timeout'),
            collection_formats=collection_formats)
