# coding: utf-8

"""
    Harmony Connect

    An easy to use API that helps you access the Factom blockchain.  # noqa: E501

    OpenAPI spec version: 1.0.17
    Contact: harmony-support@factom.com
    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 harmony_connect_client.api_client import ApiClient


class EntriesApi(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 get_entries_by_chain_id(self, chain_id, **kwargs):  # noqa: E501
        """Get Chain's Entries  # noqa: E501

        List all entries contained on the specified chain.  # 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_entries_by_chain_id(chain_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str chain_id: Chain identifier (required)
        :param int limit: The number of items you would like back in each page.
        :param int offset: The offset parameter allows you to select which item you would like to start from when you get back a list from Connect. For example, if you've already seen the first 15 items and you'd like the next set, you would send an offset of 15. `offset=0` starts from the first item of the set and is the default position.
        :param str stages: The immutability stages you want to restrict results to. You can choose any from `replicated`, `factom`, and `anchored`. If you would like to search among multiple stages, send them in a comma separated string. For example: `'replicated,factom'`.
        :return: EntryList
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.get_entries_by_chain_id_with_http_info(chain_id, **kwargs)  # noqa: E501
        else:
            (data) = self.get_entries_by_chain_id_with_http_info(chain_id, **kwargs)  # noqa: E501
            return data

    def get_entries_by_chain_id_with_http_info(self, chain_id, **kwargs):  # noqa: E501
        """Get Chain's Entries  # noqa: E501

        List all entries contained on the specified chain.  # 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_entries_by_chain_id_with_http_info(chain_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str chain_id: Chain identifier (required)
        :param int limit: The number of items you would like back in each page.
        :param int offset: The offset parameter allows you to select which item you would like to start from when you get back a list from Connect. For example, if you've already seen the first 15 items and you'd like the next set, you would send an offset of 15. `offset=0` starts from the first item of the set and is the default position.
        :param str stages: The immutability stages you want to restrict results to. You can choose any from `replicated`, `factom`, and `anchored`. If you would like to search among multiple stages, send them in a comma separated string. For example: `'replicated,factom'`.
        :return: EntryList
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = ['chain_id', 'limit', 'offset', 'stages']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_entries_by_chain_id" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']
        # verify the required parameter 'chain_id' is set
        if ('chain_id' not in local_var_params or
                local_var_params['chain_id'] is None):
            raise ValueError("Missing the required parameter `chain_id` when calling `get_entries_by_chain_id`")  # noqa: E501

        collection_formats = {}

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

        query_params = []
        if 'limit' in local_var_params:
            query_params.append(('limit', local_var_params['limit']))  # noqa: E501
        if 'offset' in local_var_params:
            query_params.append(('offset', local_var_params['offset']))  # noqa: E501
        if 'stages' in local_var_params:
            query_params.append(('stages', local_var_params['stages']))  # noqa: E501

        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 = ['AppId', 'AppKey']  # noqa: E501

        return self.api_client.call_api(
            '/chains/{chain_id}/entries', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='EntryList',  # 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_entry_by_hash(self, chain_id, entry_hash, **kwargs):  # noqa: E501
        """Get Entry Info  # noqa: E501

        Returns information about a specific entry on Connect. The requested entry must be specified using the Chain ID and Entry Hash.  # 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_entry_by_hash(chain_id, entry_hash, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str chain_id: Chain identifier (required)
        :param str entry_hash: The SHA256 hash of the entry. (required)
        :return: Entry
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.get_entry_by_hash_with_http_info(chain_id, entry_hash, **kwargs)  # noqa: E501
        else:
            (data) = self.get_entry_by_hash_with_http_info(chain_id, entry_hash, **kwargs)  # noqa: E501
            return data

    def get_entry_by_hash_with_http_info(self, chain_id, entry_hash, **kwargs):  # noqa: E501
        """Get Entry Info  # noqa: E501

        Returns information about a specific entry on Connect. The requested entry must be specified using the Chain ID and Entry Hash.  # 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_entry_by_hash_with_http_info(chain_id, entry_hash, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str chain_id: Chain identifier (required)
        :param str entry_hash: The SHA256 hash of the entry. (required)
        :return: Entry
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = ['chain_id', 'entry_hash']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_entry_by_hash" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']
        # verify the required parameter 'chain_id' is set
        if ('chain_id' not in local_var_params or
                local_var_params['chain_id'] is None):
            raise ValueError("Missing the required parameter `chain_id` when calling `get_entry_by_hash`")  # noqa: E501
        # verify the required parameter 'entry_hash' is set
        if ('entry_hash' not in local_var_params or
                local_var_params['entry_hash'] is None):
            raise ValueError("Missing the required parameter `entry_hash` when calling `get_entry_by_hash`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'chain_id' in local_var_params:
            path_params['chain_id'] = local_var_params['chain_id']  # noqa: E501
        if 'entry_hash' in local_var_params:
            path_params['entry_hash'] = local_var_params['entry_hash']  # 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 = ['AppId', 'AppKey']  # noqa: E501

        return self.api_client.call_api(
            '/chains/{chain_id}/entries/{entry_hash}', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='Entry',  # 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_first_entry(self, chain_id, **kwargs):  # noqa: E501
        """Get Chain's First Entry  # noqa: E501

        Retrieve the first entry that has been saved to this chain.  # 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_first_entry(chain_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str chain_id: Chain identifier (required)
        :return: Entry
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.get_first_entry_with_http_info(chain_id, **kwargs)  # noqa: E501
        else:
            (data) = self.get_first_entry_with_http_info(chain_id, **kwargs)  # noqa: E501
            return data

    def get_first_entry_with_http_info(self, chain_id, **kwargs):  # noqa: E501
        """Get Chain's First Entry  # noqa: E501

        Retrieve the first entry that has been saved to this chain.  # 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_first_entry_with_http_info(chain_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str chain_id: Chain identifier (required)
        :return: Entry
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = ['chain_id']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_first_entry" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']
        # verify the required parameter 'chain_id' is set
        if ('chain_id' not in local_var_params or
                local_var_params['chain_id'] is None):
            raise ValueError("Missing the required parameter `chain_id` when calling `get_first_entry`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'chain_id' in local_var_params:
            path_params['chain_id'] = local_var_params['chain_id']  # 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 = ['AppId', 'AppKey']  # noqa: E501

        return self.api_client.call_api(
            '/chains/{chain_id}/entries/first', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='Entry',  # 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_last_entry(self, chain_id, **kwargs):  # noqa: E501
        """Get Chain's Last Entry  # noqa: E501

        Retrieve the last entry that has been saved to this chain.  # 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_last_entry(chain_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str chain_id: Chain identifier (required)
        :return: Entry
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.get_last_entry_with_http_info(chain_id, **kwargs)  # noqa: E501
        else:
            (data) = self.get_last_entry_with_http_info(chain_id, **kwargs)  # noqa: E501
            return data

    def get_last_entry_with_http_info(self, chain_id, **kwargs):  # noqa: E501
        """Get Chain's Last Entry  # noqa: E501

        Retrieve the last entry that has been saved to this chain.  # 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_last_entry_with_http_info(chain_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str chain_id: Chain identifier (required)
        :return: Entry
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = ['chain_id']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_last_entry" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']
        # verify the required parameter 'chain_id' is set
        if ('chain_id' not in local_var_params or
                local_var_params['chain_id'] is None):
            raise ValueError("Missing the required parameter `chain_id` when calling `get_last_entry`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'chain_id' in local_var_params:
            path_params['chain_id'] = local_var_params['chain_id']  # 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 = ['AppId', 'AppKey']  # noqa: E501

        return self.api_client.call_api(
            '/chains/{chain_id}/entries/last', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='Entry',  # 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 post_entries_search(self, chain_id, search_body, **kwargs):  # noqa: E501
        """Search Chain's Entries  # noqa: E501

        Find all of the entries within the specified chain that have the requested `external_ids`.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.post_entries_search(chain_id, search_body, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str chain_id: Chain identifier (required)
        :param SearchBody search_body: (required)
        :param int limit: The number of items you would like back in each page.
        :param int offset: The offset parameter allows you to select which item you would like to start from when you get back a list from Connect. For example, if you've already seen the first 15 items and you'd like the next set, you would send an offset of 15. `offset=0` starts from the first item of the set and is the default position.
        :return: EntrySearchResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.post_entries_search_with_http_info(chain_id, search_body, **kwargs)  # noqa: E501
        else:
            (data) = self.post_entries_search_with_http_info(chain_id, search_body, **kwargs)  # noqa: E501
            return data

    def post_entries_search_with_http_info(self, chain_id, search_body, **kwargs):  # noqa: E501
        """Search Chain's Entries  # noqa: E501

        Find all of the entries within the specified chain that have the requested `external_ids`.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.post_entries_search_with_http_info(chain_id, search_body, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str chain_id: Chain identifier (required)
        :param SearchBody search_body: (required)
        :param int limit: The number of items you would like back in each page.
        :param int offset: The offset parameter allows you to select which item you would like to start from when you get back a list from Connect. For example, if you've already seen the first 15 items and you'd like the next set, you would send an offset of 15. `offset=0` starts from the first item of the set and is the default position.
        :return: EntrySearchResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = ['chain_id', 'search_body', 'limit', 'offset']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method post_entries_search" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']
        # verify the required parameter 'chain_id' is set
        if ('chain_id' not in local_var_params or
                local_var_params['chain_id'] is None):
            raise ValueError("Missing the required parameter `chain_id` when calling `post_entries_search`")  # noqa: E501
        # verify the required parameter 'search_body' is set
        if ('search_body' not in local_var_params or
                local_var_params['search_body'] is None):
            raise ValueError("Missing the required parameter `search_body` when calling `post_entries_search`")  # noqa: E501

        collection_formats = {}

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

        query_params = []
        if 'limit' in local_var_params:
            query_params.append(('limit', local_var_params['limit']))  # noqa: E501
        if 'offset' in local_var_params:
            query_params.append(('offset', local_var_params['offset']))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'search_body' in local_var_params:
            body_params = local_var_params['search_body']
        # 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 = ['AppId', 'AppKey']  # noqa: E501

        return self.api_client.call_api(
            '/chains/{chain_id}/entries/search', 'POST',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='EntrySearchResponse',  # 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 post_entry_to_chain_id(self, chain_id, entry_create, **kwargs):  # noqa: E501
        """Create an Entry  # noqa: E501

        Create a new entry for the selected chain. Content and external id must be uploaded in Base64 format.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.post_entry_to_chain_id(chain_id, entry_create, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str chain_id: Chain identifier (required)
        :param EntryCreate entry_create: (required)
        :return: EntryShort
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.post_entry_to_chain_id_with_http_info(chain_id, entry_create, **kwargs)  # noqa: E501
        else:
            (data) = self.post_entry_to_chain_id_with_http_info(chain_id, entry_create, **kwargs)  # noqa: E501
            return data

    def post_entry_to_chain_id_with_http_info(self, chain_id, entry_create, **kwargs):  # noqa: E501
        """Create an Entry  # noqa: E501

        Create a new entry for the selected chain. Content and external id must be uploaded in Base64 format.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.post_entry_to_chain_id_with_http_info(chain_id, entry_create, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str chain_id: Chain identifier (required)
        :param EntryCreate entry_create: (required)
        :return: EntryShort
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = ['chain_id', 'entry_create']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method post_entry_to_chain_id" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']
        # verify the required parameter 'chain_id' is set
        if ('chain_id' not in local_var_params or
                local_var_params['chain_id'] is None):
            raise ValueError("Missing the required parameter `chain_id` when calling `post_entry_to_chain_id`")  # noqa: E501
        # verify the required parameter 'entry_create' is set
        if ('entry_create' not in local_var_params or
                local_var_params['entry_create'] is None):
            raise ValueError("Missing the required parameter `entry_create` when calling `post_entry_to_chain_id`")  # noqa: E501

        collection_formats = {}

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

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'entry_create' in local_var_params:
            body_params = local_var_params['entry_create']
        # 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 = ['AppId', 'AppKey']  # noqa: E501

        return self.api_client.call_api(
            '/chains/{chain_id}/entries', 'POST',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='EntryShort',  # 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)
